In the following example, one animation will complete, and the other will keep going (because playState is not equal to 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)
}
Why does one animation never get "finished"?