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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.