+ 2
How do I stop or pause the request animationFrame() ?
I want to pause an animation frame when a condition tests true. So far I haven't been able to do so with the cancelAnimationFrame(). this is what I have tried so far function start(){ ..... if(condition){ //i don't know what next to do to stop/pause the animation } requestAnimationFrame(start) }
1 Odpowiedź
+ 2
All you need to do is not call `requestAnimationFrame` to stop the animation.
let stopped = false;
function start() {
// do stuff ...
if(!stopped)
requestAnimationFrame(start);
}
Or if you want to be fancy about it, you can pack it in a function:
https://code.sololearn.com/WC2tB5i2QCQy/?ref=app