【发布时间】:2021-08-06 08:11:38
【问题描述】:
在下面的例子中,一个动画会完成,另一个会继续播放(因为playState不等于finished):
const keyframes = new KeyframeEffect(null, [
{ // from
opacity: 0,
},
{ // to
opacity: 1,
}
], {duration: 2000, easing: 'ease'})
{
const anim = new Animation(
keyframes,
document.timeline
)
anim.play()
requestAnimationFrame(function loop() {
console.log('1', keyframes.getComputedTiming().progress)
if (anim.playState != 'finished') requestAnimationFrame(loop)
}, 100)
}
{
const anim = new Animation(
keyframes,
document.timeline
)
anim.play()
requestAnimationFrame(function loop() {
console.log('2', keyframes.getComputedTiming().progress)
if (anim.playState != 'finished') requestAnimationFrame(loop)
}, 100)
}
为什么一个动画永远不会“完成”?
【问题讨论】: