作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
// 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})
, set 0 to 0.0001?
我误解了值(value)变化的意思。如果我想要结束值是 0
,参数 c
应该是 -20
最佳答案
对于easeInQuad的后续执行
easeInQuad(100, 20, 0, 1000)
我得到 20,因为你的大部分公式都乘以 0。
0*(100/=1000)*100 + 20 = 20
在查看其他缓动公式后,我认为这是预期的行为。查看 jQuery 源代码 here
进一步的测试表明,将 0 更改为 1 应该会产生 20.01,并且这种趋势仍在继续。我再次认为这是预期的行为。
关于javascript - JavaScript 中的缓动函数 - 将值的变化设置为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32621836/
我是一名优秀的程序员,十分优秀!