Skip to content

Instantly share code, notes, and snippets.

@webinista
Created September 4, 2012 21:42
Show Gist options
  • Save webinista/3626934 to your computer and use it in GitHub Desktop.
Save webinista/3626934 to your computer and use it in GitHub Desktop.
Testing for CSS 3D Transforms Support
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;
}
}
@lorenzopolidori
Copy link

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)';

@webinista
Copy link
Author

Suprisingly, it works either way, at least in newer versions of each browser. But yes, you are right.

@brad2k
Copy link

brad2k commented Dec 10, 2012

This wasn't working for me in IE10. msTransform works for me, but MSTransform does not.

@A-n-d-r-e-a-s-M
Copy link

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