-
Notifications
You must be signed in to change notification settings - Fork 1
/
Motionizer.min.js
3 lines (3 loc) · 1.2 KB
/
Motionizer.min.js
1
2
3
var Motionizer=function(e,f){window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)}}();var h=!!window.DeviceOrientationEvent,c,i="undefined"==typeof f?!0:f,d=0,a={ev:{},getX:function(){return a.ev.gamma||0},getY:function(){return a.ev.beta||0},getOrientZ:function(){return a.ev.alpha||0},getXDeg:function(){switch(d){case 90:return-a.getX();
case 0:return a.getY();case -90:return a.getX();case 180:return a.getY()}},getYDeg:function(){switch(d){case 90:return-a.getY();case 0:return-a.getX();case -90:return a.getY();case 180:return a.getX()}},getZDeg:function(){return a.getOrientZ()}},g=function(){requestAnimFrame(g);var b="rotateX("+a.getXDeg()+"deg) rotateY("+a.getYDeg()+"deg)";i&&(b+="rotateZ("+a.getZDeg()+"deg)");c.style.webkitTransform=b;c.style.mozTransform=b;c.style.transform=b};(function(){h&&(c="object"==typeof e?e:document.getElementById(e),
window.addEventListener("deviceorientation",function(b){a.ev=b},!1),window.addEventListener("orientationchange",function(){d=window.orientation},!1),d=window.orientation,g())})()};