So I know that you can assign setInterval to a variable, and later pass that variable to clearInterval to disable the timer.
What I'm wondering:
Say I have a global variable that is null on page initiation. When a specific function gets called then the global variable is assigned setInterval(fname, seconds). When I don't want this interval running anymore, I set the global variable to null.
For what I'm specifically testing (a sequence of images being rendered one after the other) it seems to work, but I wonder if I'm making some sneaky error.
Here's an overview of my code:
MyStuff.controls = {};
MyStuff.controls.animation_timer = null;
MyStuff.controls.start = function () {
if (!MyStuff.controls.animation_timer) {
MyStuff.controls.animation_timer = setInterval(MyStuff.controls.animate, 500);
}
}
MyStuff.controls.stop = function () {
MyStuff.controls.animation_timer = null;
}
I made a mistake. I was calling clearInterval I just didn't see it for whatever reason - the example I presented won't work. Sorry everyone!