我无法识别 step() 函数中的一行来指示动画已完成。因此,我无法正确取消AnimationFrame。
问题:这是 cancelAnimationFrame() 不起作用的原因吗?如果是,我应该在哪一行代码中指示动画已经完成,以便我可以取消AnimationFrame?
var myRequestId;
function step() {
// ... see https://codepen.io/jek/pen/RwwXBpz
myRequestId = requestAnimationFrame(step);
console.log("myRequestId", myRequestId);
}
myRequestId = requestAnimationFrame(step);
// Ref https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelAnimationFrame
// todo: How do we stop it onComplete?
// question: where do we put a flag to indicate that it has completed?
//cancelAnimationFrame(myRequestId); // todo: If we uncomment this line the animation won't work at all