Skip to content

Instantly share code, notes, and snippets.

@stardines
Forked from lorenzopolidori/has3d.js
Created September 23, 2015 14:06
Show Gist options
  • Save stardines/8e5d6c513e960479bb5b to your computer and use it in GitHub Desktop.
Save stardines/8e5d6c513e960479bb5b to your computer and use it in GitHub Desktop.
Testing for CSS 3D Transforms Support
function has3d(){
if (!window.getComputedStyle) {
return false;
}
var el = document.createElement('p'),
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, null);
for(var t in transforms){
if( el.style[t] !== undefined ){
el.style[t] = 'translate3d(1px,1px,1px)';
has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
}
}
document.body.removeChild(el);
return (has3d !== undefined && has3d.length > 0 && has3d !== "none");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment