Setinterval & Settimeout?
I want to stop my javascript after x seconds, I saw that the function is setTimeout, I tried to add that to my code but no succes, is this the better way to do this? Thanks for you
Solution 1:
Initialize your interval in a variable and clear it after X
(here 2) seconds:
var interval = setInterval(blink, 300);
setTimeout(function() {
clearInterval(interval);
}, 2000);
Solution 2:
use like this:
var myvar;
functionmyStartFunction()
{
myvar=setInterval(function(){blink()},300);
}
functionmyStopFunction()
{
clearInterval(myvar);
}
Post a Comment for "Setinterval & Settimeout?"