【发布时间】:2017-10-13 04:20:10
【问题描述】:
如果可以的话,我会很乐意为此使用图书馆吗?或对我的 psuedocode api 的任何其他建议。
问题:
如何编写一个接受 4 个参数 interpolate(start, end, time, ease) 的函数,并随着时间的推移轻松地对开始到结束的数字进行插值?
问题:
这感觉特别难,因为我不知道如何在请求动画帧中控制时间或缓和。其次,我不知道如何编写贝塞尔曲线处理程序。最后,根据需要进行优化。
interpolate(start:number, end:number, time:number, ease) {
// easing
return value;
}
function _draw() {
currentValue = interpolate(0, 10, 0.7, 'cubic-bezier(.62,.28,.23,.99)');
if(currentValue !== lastValue) {
console.log(currentValue)
}
requestAnimationFrame(_draw);
}
所以最后 currentValue 会在 0.7 的最后一个刻度中注销 10。
【问题讨论】:
标签: javascript animation interpolation requestanimationframe