I am calling this function
function drawLayers() {
//setTimeout(drawBlueSky,500);
//setTimeout(drawCircle1,1250);
setTimeout(drawMoon,800);
The common way to do this is using clearTimeout
:
var myTimeout = setTimeout(function(){
alert('hi');
}, 500);
clearTimeout(myTimeout); // No 'hi' alert for you, sir
But in your case, I would propose a more concise way of controlling all the timeouts:
var keepRunning = true;
var timeouts = {
drawMoon: 800,
drawCircle1: 2300,
drawCircle2: 2700,
drawCircle3: 3100,
drawCircle4: 3500
// etc...
};
for(var func in timeouts)
var timeout = setTimeout(func, timeouts[func]);
// just demonstrating a timeout run function here, such as "drawMoon":
var drawMoon = function(){
...
if(!keepRunning)
return;
...
// probably conditionally
keepRunning = false;
...
};