var Tween = {
線性:函數(t,b,c,d){ return c*t/d b; },
四元組:{
easeIn: 函數(t,b,c,d){
return c*(t/=d)*t b;
},
easeOut : 函數(t,b,c,d){
return -c *(t/=d)*(t-2) b;
},
escapeInOut: 函數(t,b,c ,d ){
if ((t/=d/2) return -c/2 * ((--t)*(t-2) - 1) b;
}
},
三次:{
easyIn: function(t,b,c,d){
return c*(t/=d)*t * t b;
},
escapeOut: function(t,b,c,d){
return c*((t=t/d-1)*t*t 1) b;
},
easyInOut: function(t,b,c,d){
if ((t/=d/2) return c/2*((t-=2)*t*t 2) b;
}
},
誇脫:{
easeIn:函數(t,b,c,d) {
return c*(t/=d)*t*t*t b;
},
escapeOut: function(t,b,c,d){
return -c * (( t =t/d-1)*t*t*t - 1) b;
},
easeInOut: function(t,b,c,d){
if ((t/=d / 2) return -c/2 * ((t-=2)*t*t*t - 2) b;
}
},
五元組:{
easeIn: function(t,b,c,d){
return c*(t/=d)*t*t*t*t b;
},
escapeOut: function(t,b,c,d){
return c*((t=t/d-1)*t*t*t*t 1) b;
},
escapeInOut: 函數(t,b,c,d){
if ((t/=d/2) return c/2*((t-=2)*t*t*t*t 2) b;
}
},
正弦:{
escapeIn: function(t,b,c,d){
return -c * Math.cos(t/d * (Math.PI/2)) c b;
},
escapeOut: function(t,b,c,d){
return c * Math.sin(t/d * (Math.PI/2)) b;
},
escapeInOut: function(t,b,c,d){
return -c/2 * (Math.cos(Math.PI*t/d) - 1) b;
}
},
東南:{
easeIn: function(t,b,c,d){
return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) b;
},
escapeOut: function(t,b,c,d){
return (t= =d)? > if (t ==0) return b;
if (t==d) return b c;
if ((t/=d/2) return c/2 * (-Math.pow(2, -10 * --t) 2) b;
}
},
循環:{
escapeIn: function(t,b,c,d){
return -c * (Math.sqrt(1 - (t/=d)*t) - 1) b;
},
escapeOut: function(t,b,c,d){
return c * Math.sqrt(1 - (t=t/d-1)*t) b;
},
easyInOut : 函數(t,b,c,d){
if ((t/=d/2) return c/2 * (Math.sqrt(1 - (t-=2)*t) 1) b;
}
},
彈性: {
ease : 函數(t,b,c,d,a,p){
如果(t==0) 回傳b; if ((t/=d)==1) 回傳b c; if (!p) p =d*.3;
if (!a || a else var s = p/(2*Math .PI) * Math.asin (c/a);
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2* Math.PI)/p ) ) b;
},
easeOut: 函數(t,b,c,d,a,p){
如果(t==0) 回傳b; if ((t/=d)==1) 返回 b c; if (!p) p=d*.3;
if (!a || a else var s = p/(2*Math.PI) * Math.asin (c/a);
return (a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) c b);
},
escapeInOut: 函數(t,b,c,d,a,p){
if (t ==0)返回b; if ((t/=d/2)==2) 返回b c; if (!p) p=d*(.3*1.5);
if (!a || a else var s = p/(2*Math.PI) * Math.asin (c/a);
if (t return a*Math.pow(2,-10*( t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 c b;
}
},
回傳:{
escapeIn: function(t,b,c,d,s){
if (s == undefined) s = 1.70158;
/=d)*t*((s 1)* t - s) b;
},
escapeOut: function(t,b,c,d,s){
if (s == undefined) s = 1.70158;
return c*( (t=t/d-1)*t*((s 1)*t s) 1) b;
},
escapescape: 函數(tInOut ,b,c,d,s){
if (s == undefined) s = 1.70158;
if ((t/=d/2) return c/2*((t-=2)*t*(((s* =(1.525)) 1) *t s) 2) b;
}
},
Bounce: {
easeIn: function(t,b,c,d){
return c - Tween.Bounce.easeOut(d-t, 0, c, d) b;
},
easeOut: function(t,b,c,d){
if ((t/=d) return c*(7.5625*t*t) b;
} else if (t return c*(7.5625*(t-=(1.5/2.75))*t .75) b;
return c*(7.5625*(t-=(2.25/2.75))*t .9375) b;
} else {
return,75. t-=(2.625/2.75))*t .984375) b;
}
},
easeInOut: function(t,b,c,d){
easeInOut: function(t,b,c,d){
ease if (t else return Tween.Bounce.easeOut(t*2-d, 0, c, d) * .5 c*.5 b;
}
}
}
其中每種緩動方式對應3種類型
easeIn:從0開始加速的緩動;
easeOut:減速到0的緩動;
easeInOut:前半段從0開始加速,後半段減速到0的緩動
參數說明:
t:當前時間
b:初始值
c:變化量
d:持續時間呼叫方式:
程式碼如下:
var timer = nullm
var timer = nullm
var drag = $("drag");
.Circ .easeInOut(t,b,c,d)) "px";
if(t else{
clearInterval(timer);
}
}var timer = setInterval(run, 20);