Last active
March 12, 2016 14:29
-
-
Save milosdjakonovic/787b44e69fe053e18427 to your computer and use it in GitHub Desktop.
Real3d detects support for csstransforms3d and gives result both to html classes and javascript property
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
/** | |
* | |
* real3d detects support for csstransforms3d and gives | |
* result both to html classes and javascript property | |
* (just like Modernizr does) | |
* | |
* Unlike Modernizr, it's doing this non trivial test | |
* on real element inside real document's body, relaying | |
* on computated css transform property as distinctive | |
* factor for testing. | |
* | |
* - created because of many false positives and false negatives of Modernizr.csstransforms3d | |
* - 0.5KB size | |
* - to be inserted in document's body (for fastest result, right after <body>) | |
* - tested on many browsers, never gave me bllsht | |
* | |
**/ | |
(function(w,d){ | |
var pref = ['Webkit', 'Moz', 'ms', 'O'], | |
div = d.createElement('div'), | |
body = d.getElementsByTagName('body')[0], | |
fRtrn, | |
resultPublisher = function(result){ | |
w.real3d=result; | |
d.documentElement.className += (result) ? ' real3d' : ' no-real3d'; | |
} | |
if(! 'getComputedStyle' in w){ | |
resultPublisher (false); | |
return; | |
} | |
function checkDivsTransform(dv){ | |
var trProp=false; | |
if('transform' in dv.style) trProp='transform'; | |
else{ | |
for (var i = 0; i < 4; i++) { | |
if( pref[i]+'Transform' in dv.style ){ | |
trProp=pref[i]+'Transform'; | |
} | |
} | |
} | |
if(!trProp) return false; | |
dv.style[trProp]='rotateY(2deg)'; | |
fRtrn = (w.getComputedStyle(dv,false)[trProp].indexOf('matrix3d')!==-1); | |
body.removeChild(dv); | |
return fRtrn; | |
} | |
body.appendChild(div); | |
resultPublisher (checkDivsTransform(div)); | |
pref = div = body = null; | |
})(window,document); |
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
// real3d.js|@Miloshio|2016 | |
!function(e,n){function t(n){var t=!1;if("transform"in n.style)t="transform";else for(var a=0;4>a;a++)o[a]+"Transform"in n.style&&(t=o[a]+"Transform");return t?(n.style[t]="rotateY(2deg)",r=-1!==e.getComputedStyle(n,!1)[t].indexOf("matrix3d"),d.removeChild(n),r):!1}var r,o=["Webkit","Moz","ms","O"],a=n.createElement("div"),d=n.getElementsByTagName("body")[0],i=function(t){e.real3d=t,n.documentElement.className+=t?" real3d":" no-real3d"};return!1 in e?void i(!1):(d.appendChild(a),i(t(a)),void(o=a=d=null))}(window,document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment