ht-animation.js 5.3 KB

1
  1. !function(i){"use strict";var U="ht",K=i[U],r=K.Default,u="prototype",s=K.DataModel[u],W=K.Data[u],Q=null,$=function(F){return"set"+F.charAt(0).toUpperCase()+F.slice(1)};r.getEasing=function(U){var A=Q;return U.indexOf(".")>=0?(U=U.split("."),A=b[U[0]][U[1]]):A=b[U],function(w){return A(w,0,1,1)}},r.getCommonEasing=function(L){var p=Q;return L.indexOf(".")>=0?(L=L.split("."),p=b[L[0]][L[1]]):p=b[L],p},W.setAnimation=function(q){var O=this._animation;this._animation=q,this.fp("animation",O,q)},W.getAnimation=function(){return this._animation},i.requestAnimFrame=function(){return i.requestAnimationFrame||i.webkitRequestAnimationFrame||i.mozRequestAnimationFrame||function(x){i.setTimeout(x,1e3/60)}}();var n=i.requestAnimFrame,e=i.setInterval;s.setAnimationInterval=function(O){var P=this;P.$2a=O,P.$1a!=Q&&(clearInterval(P.$1a),delete P.$1a,P.enableAnimation(O))},s.getAnimationInterval=function(){return this.$2a||"animationFrame"},s.getDataAnimation=function(C){return C.getAnimation()},s.enableAnimation=function(w){var v=this,s=v.getDatas();if(v.$1a==Q){w&&v.setAnimationInterval(w),w=v.getAnimationInterval();var i=function(){var A=v.getAnimationInterval();s.each(function(L){var V=v.getDataAnimation(L);if(L.setAnimation(V),V){var Y=V.start;L._animationstatus=L._animationstatus||{},L._animationprocess=L._animationprocess||Y.slice(0);for(var W=L._animationstatus,p=L._animationprocess,N=0;N<p.length;N++){var q;q=W[N]?W[N]:W[N]={$5a:0,$6a:0,$7a:0,$8a:0};var R=V[p[N]],E=R.property,y=R.accessType,k=R.from,o=R.to,z=R.easing||"Quad.easeOut",f=q.$5a,s=R.frames||60,F=R.repeat||0,B=R.delay||0,C=R.interval,x=q.$6a,M=R.onUpdate,d=R.onComplete,_=!1,T=function(){var i=r.getCommonEasing(z)(f,k,o-k,s);M?M.call(L,i):y?"style"===y?L.s(E,i):"attr"===y?L.a(E,i):"field"===y&&(L[E]=i):L[$(E)](i),_=!0},K=function(){C!=Q?q.$7a>=C?(q.$7a=0,T()):q.$7a+=isNaN(A)?16.6666:A:T()};B?q.$8a>=B?K():q.$8a+=isNaN(A)?16.6666:A:K(),_&&(f=q.$5a=f+1,f>s&&(F===!0?f=q.$5a=0:(x=q.$6a=x+1,x>F&&(d&&d.call(L),R.next?(W[N]=Q,p[N]=R.next):L.setAnimation(null)))))}}}),"animationFrame"===A&&v.$1a!=Q&&(v.$1a=n(i))};v.$1a="animationFrame"===w?n(i):e(i,w)}},s.disableAnimation=function(){var G=this,C=G.getAnimationInterval();"animationFrame"===C||clearInterval(G.$1a),delete G.$1a};var b={Linear:function(k,p,Y,w){return Y*k/w+p},Quad:{easeIn:function(Q,N,t,V){return t*(Q/=V)*Q+N},easeOut:function(l,W,o,s){return-o*(l/=s)*(l-2)+W},easeInOut:function(c,i,w,q){return(c/=q/2)<1?w/2*c*c+i:-w/2*(--c*(c-2)-1)+i}},Cubic:{easeIn:function(C,m,e,I){return e*(C/=I)*C*C+m},easeOut:function(Z,R,L,r){return L*((Z=Z/r-1)*Z*Z+1)+R},easeInOut:function(X,o,c,e){return(X/=e/2)<1?c/2*X*X*X+o:c/2*((X-=2)*X*X+2)+o}},Quart:{easeIn:function(o,m,l,D){return l*(o/=D)*o*o*o+m},easeOut:function(y,H,w,a){return-w*((y=y/a-1)*y*y*y-1)+H},easeInOut:function(x,Q,i,b){return(x/=b/2)<1?i/2*x*x*x*x+Q:-i/2*((x-=2)*x*x*x-2)+Q}},Quint:{easeIn:function(x,e,T,o){return T*(x/=o)*x*x*x*x+e},easeOut:function(W,E,m,N){return m*((W=W/N-1)*W*W*W*W+1)+E},easeInOut:function(s,k,E,F){return(s/=F/2)<1?E/2*s*s*s*s*s+k:E/2*((s-=2)*s*s*s*s+2)+k}},Sine:{easeIn:function(e,F,j,y){return-j*Math.cos(e/y*(Math.PI/2))+j+F},easeOut:function(p,C,q,V){return q*Math.sin(p/V*(Math.PI/2))+C},easeInOut:function(J,X,G,j){return-G/2*(Math.cos(Math.PI*J/j)-1)+X}},Expo:{easeIn:function(d,X,C,Q){return 0==d?X:C*Math.pow(2,10*(d/Q-1))+X},easeOut:function(c,A,B,M){return c==M?A+B:B*(-Math.pow(2,-10*c/M)+1)+A},easeInOut:function(K,M,d,C){return 0==K?M:K==C?M+d:(K/=C/2)<1?d/2*Math.pow(2,10*(K-1))+M:d/2*(-Math.pow(2,-10*--K)+2)+M}},Circ:{easeIn:function(l,n,U,e){return-U*(Math.sqrt(1-(l/=e)*l)-1)+n},easeOut:function(o,E,F,h){return F*Math.sqrt(1-(o=o/h-1)*o)+E},easeInOut:function(G,S,U,p){return(G/=p/2)<1?-U/2*(Math.sqrt(1-G*G)-1)+S:U/2*(Math.sqrt(1-(G-=2)*G)+1)+S}},Elastic:{easeIn:function(k,z,H,T,q,m){var n;return 0==k?z:1==(k/=T)?z+H:("undefined"==typeof m&&(m=.3*T),!q||q<Math.abs(H)?(n=m/4,q=H):n=m/(2*Math.PI)*Math.asin(H/q),-(q*Math.pow(2,10*(k-=1))*Math.sin((k*T-n)*2*Math.PI/m))+z)},easeOut:function(C,O,K,H,M,n){var g;return 0==C?O:1==(C/=H)?O+K:("undefined"==typeof n&&(n=.3*H),!M||M<Math.abs(K)?(M=K,g=n/4):g=n/(2*Math.PI)*Math.asin(K/M),M*Math.pow(2,-10*C)*Math.sin((C*H-g)*2*Math.PI/n)+K+O)},easeInOut:function(G,y,m,g,p,A){var i;return 0==G?y:2==(G/=g/2)?y+m:("undefined"==typeof A&&(A=g*.3*1.5),!p||p<Math.abs(m)?(p=m,i=A/4):i=A/(2*Math.PI)*Math.asin(m/p),1>G?-.5*p*Math.pow(2,10*(G-=1))*Math.sin((G*g-i)*2*Math.PI/A)+y:.5*p*Math.pow(2,-10*(G-=1))*Math.sin((G*g-i)*2*Math.PI/A)+m+y)}},Back:{easeIn:function(k,h,N,w,f){return"undefined"==typeof f&&(f=1.70158),N*(k/=w)*k*((f+1)*k-f)+h},easeOut:function(E,r,z,s,h){return"undefined"==typeof h&&(h=1.70158),z*((E=E/s-1)*E*((h+1)*E+h)+1)+r},easeInOut:function(k,d,f,Y,v){return"undefined"==typeof v&&(v=1.70158),(k/=Y/2)<1?f/2*k*k*(((v*=1.525)+1)*k-v)+d:f/2*((k-=2)*k*(((v*=1.525)+1)*k+v)+2)+d}},Bounce:{easeIn:function(J,Y,T,x){return T-b.Bounce.easeOut(x-J,0,T,x)+Y},easeOut:function(n,L,Y,G){return(n/=G)<1/2.75?Y*7.5625*n*n+L:2/2.75>n?Y*(7.5625*(n-=1.5/2.75)*n+.75)+L:2.5/2.75>n?Y*(7.5625*(n-=2.25/2.75)*n+.9375)+L:Y*(7.5625*(n-=2.625/2.75)*n+.984375)+L},easeInOut:function(K,z,G,W){return W/2>K?.5*b.Bounce.easeIn(2*K,0,G,W)+z:.5*b.Bounce.easeOut(2*K-W,0,G,W)+.5*G+z}}}}("undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:this,Object);