// t: current time, b: beginning value, c: change in value, d: duration
function easeInQuad(t, b, c, d) {
return c*(t/=d)*t + b;
}
function easeOutElastic(t, b, c, d) {
var s = 1.70158;
var p = 0;
var a = c;
if (t == 0) return b;
if ((t /= d) == 1) return b + c;
if (!p) p = d * .3;
if (a < Math.abs(c)) {
a = c;
var s = p / 4;
} 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;
}
easeInQuad(100, 20, 0, 1000) // 20
easeInQuad(500, 20, 0, 1000) // 20
easeOutElastic(0, 20, 0, 1000) // 20
easeOutElastic(500, 20, 0, 1000) // NaN
easeOutElastic(1000, 20, 0, 1000) // 20
如果值变化为 0,easeInQuad
则始终返回 20,easeOutElastic
也返回错误值。
值的变化不能为 0 吗?jQuery如何处理animate({top: 0})
,设置0到0.0001?
我误解了价值变化的含义。如果我想要最终值0
,参数c
应该是-20