I could not identify a line in step() function to indicate that the animation has completed. Therefore, I could not cancelAnimationFrame correctly.
Question: Is this the reason why cancelAnimationFrame() is not working? If yes, at which line of code do I indicate that animation has completed so I can cancelAnimationFrame?
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