Created
September 4, 2012 21:42
-
-
Save webinista/3626934 to your computer and use it in GitHub Desktop.
Testing for CSS 3D Transforms Support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function has3d(){ | |
var el = document.createElement('p'), t, has3d, | |
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, document.body.lastChild); | |
for(t in transforms){ | |
if( el.style[t] !== undefined ){ | |
el.style[t] = 'matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)'; | |
has3d = window.getComputedStyle(el).getPropertyValue( transforms[t] ); | |
} | |
} | |
if( has3d !== undefined ){ | |
return has3d !== 'none'; | |
} else { | |
return false; | |
} | |
} |
Suprisingly, it works either way, at least in newer versions of each browser. But yes, you are right.
This wasn't working for me in IE10. msTransform works for me, but MSTransform does not.
document.body.insertBefore(el, document.body.lastChild); does not seem to be necessary. I removed it and the script is still working on my desktop ie11 (emulation mode: ie10,11: true, 9 and below false), firefox and chrome.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To make it work properly, you should have:
'MozTransform':'-moz-transform',
and
el.style[ t ] = 'matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)';