requestAnimationFrame returns a long integer. If you assign that to a variable, you can then call cancelAnimationFrame(id) once the required condition is met to stop the cycle.
Using the step function as an example, something like this:
letanimationFrameId;functionstep(){if(animationFrameId&&conditionToStopCycle){window.cancelAnimationFrame(animationFrameId);return;}// rest of the codeanimationFrameId=window.requestAnimationFrame(step);}
Another way could be to return early to break out of the step function. If only one cycle is needed, once the counter reaches the end of the array, return before calling the next requestAnimationFrame (instead of reseting the counter to 0 and continuing).
requestAnimationFrame
returns a long integer. If you assign that to a variable, you can then callcancelAnimationFrame(id)
once the required condition is met to stop the cycle.Using the
step
function as an example, something like this:Another way could be to return early to break out of the
step
function. If only one cycle is needed, once the counter reaches the end of the array, return before calling the nextrequestAnimationFrame
(instead of reseting the counter to 0 and continuing).Here are the MDN pages for requestAnimationFrame and cancelAnimationFrame.
Thank you... I really appreciate your help.