Stopping Your Animation Loop

We'll cover the following...

Once your requestAnimationFrame loop starts running, rarely will you ever need to tell it to stop. If you do need to stop your animation loop from doing unnecessary work, you can do something like the following:

Press + to interact
var running = true;
function animate() {
if (running) {
// do animation or drawing stuff
}
requestAnimationFrame(animate);
}

If your running variable were to ever be set to false, your animation loop will stop doing whatever work is being done. ...