-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.trans.min.js
3 lines (2 loc) · 3.4 KB
/
jquery.trans.min.js
1
2
3
/*! trans v0.5 */
!function(a,b){"use strict";function e(a){if(a in c.style)return a;for(var b=["Moz","Webkit","O","ms"],d=a.charAt(0).toUpperCase()+a.substr(1),e="",f=0;f<b.length;f++)if(e=b[f]+d,e in c.style)return e}function f(a){var b=a.currentStyle||document.defaultView.getComputedStyle(a,""),c=!0,e=[[],[],[],[]],f=/matrix3d\((.*)\)/,g=b[d.transform].match(f);if(null===g&&(c=!1,f=/matrix\((.*)\)/,g=b[d.transform].match(f)),null===g)return e=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];g=g.slice(1)[0].split(",");for(var h=0;h<g.length;h++)g[h]=parseFloat(g[h],10);return e=c===!0?[[g[0],g[1],g[2],g[3]],[g[4],g[5],g[6],g[7]],[g[8],g[9],g[10],g[11]],[g[12],g[13],g[14],g[15]]]:[[g[0],g[1],0,0],[g[2],g[3],0,0],[0,0,1,0],[g[4],g[5],0,1]]}function g(a){var b=f(a),c=Math.atan2(b[1][2],b[2][2]),d=Math.asin(b[0][2]*-1),e=Math.atan2(b[0][1],b[0][0]);c===-0&&(c=0),d===-0&&(d=0),e===-0&&(e=0),0===Math.cos(d)&&(c=Math.atan2(b[2][0]*-1,b[1][1]),e=0);var g={x:b[3][0],y:b[3][1],z:b[3][2],rotateX:180*c/Math.PI,rotateY:180*d/Math.PI,rotateZ:180*e/Math.PI,scaleX:Math.sqrt(b[0][0]*b[0][0]+b[0][1]*b[0][1]+b[0][2]*b[0][2]),scaleY:Math.sqrt(b[1][0]*b[1][0]+b[1][1]*b[1][1]+b[1][2]*b[1][2]),scaleZ:Math.sqrt(b[2][0]*b[2][0]+b[2][1]*b[2][1]+b[2][2]*b[2][2])};return g}function h(a,b,c){var d=parseFloat(c,10);switch(b){case"translateX":a.x=d;break;case"translateY":a.y=d;break;case"translateZ":a.z=d;break;case"rotate":a.rotateZ=d;break;case"scale":a.scaleX=d,a.scaleY=d;break;case"addX":a.x+=d;break;case"addY":a.y+=d;break;case"addZ":a.z+=d;break;case"addRotate":a.rotateZ+=d;break;case"addRotateX":a.rotateX+=d;break;case"addRotateY":a.rotateY+=d;break;case"addRotateZ":a.rotateZ+=d;break;case"addScaleX":a.scaleX+=d;break;case"addScale":a.scaleX+=d,a.scaleY+=d;break;case"addScaleY":a.scaleY+=d;break;case"addScaleZ":a.scaleZ+=d;break;default:a[b]=d}}function i(a){var b=[];return(0===a.x&&0===a.y&&0===a.z)==!1&&(d.bl_transform3d===!0?b.push("translate3d("):b.push("translate("),b.push(a.x+"px,"),b.push(a.y+"px"),d.bl_transform3d===!0?(b.push(b.pop()+","),b.push(a.z+"px)")):b.push(") ")),0!==a.rotateX&&b.push("rotateX("+a.rotateX+"deg)"),0!==a.rotateY&&b.push("rotateY("+a.rotateY+"deg)"),0!==a.rotateZ&&b.push("rotateZ("+a.rotateZ+"deg)"),(1===a.scaleX&&1===a.scaleY&&1===a.scaleZ)==!1&&(1===a.scaleZ||d.bl_transform3d===!1?a.scaleX===a.scaleY?b.push("scale("+a.scaleX+")"):b.push("scale("+a.scaleX+", "+a.scaleY+")"):b.push("scale3d("+a.scaleX+", "+a.scaleY+", "+a.scaleZ+")")),b.join(" ")}var c=document.createElement("div"),d={transition:"",transitionDelay:"",transform:"",transformOrigin:"",filter:"",bl_transform3d:!0};d.transition=e("transition"),d.transitionDelay=e("transitionDelay"),d.transform=e("transform"),d.transformOrigin=e("transformOrigin"),d.filter=e("Filter"),d.bl_transform3d=function(){return c.style[d.transform]="",c.style[d.transform]="rotateY(90deg)",""!==c.style[d.transform]}(),a.fn.trans=function(b,c){var e={};if(void 0===b){var f=a(this).get(0);return e=g(f),e.support=d,a.extend(!0,{},e)}var j=["translateX","translateY","translateZ","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","x","y","z","addX","addY","addZ","addRotate","addRotateX","addRotateY","addRotateZ","addScale","addScaleX","addScaleY","addScaleZ"];return a(this).each(function(c,f){e=g(f),"object"==typeof b&&a.each(b,function(b,c){j.indexOf(b)!==-1?h(e,b,c):"transition"===b&&a(f).css(d.transition,c)}),a(f).css(d.transform,i(e))}),this}}(jQuery,window);