Why clearTimeout with millisec argument is not working?
Because you're using clearTimeout()
incorrectly. Your code needs to resemble the following:
var x = setTimeout("doStuff();", tempo);
clearTimeout(x);
You are currently using tempo
as the timeout handle, which is why it isn't working.
Use the return from setTimeout
to pass it to the clearTimeout
function :
var timeoutId = setTimeout(callBack, 1000);
//then, later in the code
clearTimeout(timeoutId);
To use clearTimeout
you need to pass it the value returned from a call to setTimeout
.
var timeout;
// ...
timeout = setTimeout('rotate('+i+', '+base+');', tempo);
// ...
clearTimeout(timeout);