做了个简单的插件,以后慢慢重构:
/**
*
* 描述:javascript缓动
* jQuery Tween算法:算法来源:http://www.robertpenner.com/easing/
* @author:xuzengqiang
* @since :2015-1-23 11:17:51
* 两种比较复杂的没有收录进来
* Elastic:指数衰减的正弦曲线缓动;
* Back:超过范围的三次方缓动((s+1)*t^3 - s*t^2);
**/
;(function($){
jQuery.extend({
Tweens:{
Linear:function(t,b,c,d){ //无缓动
return c*t/d+b;
},
Quad: { //二次方缓动(t^2)
easeIn: function(t,b,c,d){
return c*(t/=d)*t + b;
},
easeOut: function(t,b,c,d){
return -c *(t/=d)*(t-2) + b;
},
easeInOut: function(t,b,c,d){
if ((t/=d/2) < 1) return c/2*t*t + b;
return -c/2 * ((--t)*(t-2) - 1) + b;
}
},
Cubic: { //三次方缓动(t^3)
easeIn: function(t,b,c,d){
return c*(t/=d)*t*t + b;
},
easeOut: function(t,b,c,d){
return c*((t=t/d-1)*t*t + 1) + b;
},
easeInOut: function(t,b,c,d){
if ((t/=d/2) < 1) return c/2*t*t*t + b;
return c/2*((t-=2)*t*t + 2) + b;
}
},
Quart: { //四次方缓动(t^4)
easeIn: function(t,b,c,d){
return c*(t/=d)*t*t*t + b;
},
easeOut: 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) < 1) return c/2*t*t*t*t + b;
return -c/2 * ((t-=2)*t*t*t - 2) + b;
}
},
Quint: { //五次方缓动(t^5)
easeIn: function(t,b,c,d){
return c*(t/=d)*t*t*t*t + b;
},
easeOut: function(t,b,c,d){
return c*((t=t/d-1)*t*t*t*