Ok, Dr. Dale SHOW US....
window.setInterval() returns an event 'handle'
window.setInterval ( what you want to do -- usually a function , number of msec between animation frames ) window.clearInterval ( handle of event you wish to stop )
ie,
var handleName = window.setInterval ( stuff , 50 ) <-------------- do stuff every 50msec window.clearInterval ( handleName ) <------------------------------- but where does/should/might the STOPPING instruction go?!?
Here's how COUNTING was accomplished
<script> var cnt=0; // Initialization var animNum = window.setInterval( function(){ document.getElementById('num').innerHTML = cnt; if (cnt == 9) window.clearInterval(animNum); // Condition cnt ++; // Update } ,200 ); </script>
setInterval.html several animations running at once rube.html Rube Goldberg Machine-ish! More...