Skip to content

Instantly share code, notes, and snippets.

@rhysburnie
Last active October 18, 2017 10:38
Show Gist options
  • Save rhysburnie/f46cab589f937c2a526772e20924f9ec to your computer and use it in GitHub Desktop.
Save rhysburnie/f46cab589f937c2a526772e20924f9ec to your computer and use it in GitHub Desktop.
function transformsSupport() {
if (!window.getComputedStyle) {
return false;
}
var el = document.createElement('p'),
has3d,
transformPropName,
transforms = {
webkitTransform: '-webkit-transform',
OTransform: '-o-transform',
msTransform: '-ms-transform',
MozTransform: '-moz-transform',
transform: 'transform',
};
// Add it to the body to get the computed style.
document.body.insertBefore(el, null);
for (var t in transforms) {
if (has3d) {
break;
}
if (el.style[t] !== undefined) {
el.style[t] = 'translate3d(1px,1px,1px)';
has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
transformPropName = t;
}
}
if (!transformPropName) {
return false;
}
document.body.removeChild(el);
return {
mode:
has3d !== undefined && has3d.length > 0 && has3d !== 'none' ? '3d' : '2d',
transformPropName: transformPropName,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment