I have this piece of code that initially starts an interval. Then with the push of a button, I want that interval to be stopped/cleared, wait X seconds, and then start the interval again.
This code starts the interval and works fine:
var timeout = undefined;
var interval = setInterval(bgScroll, timeBetweenSwap);
Then I want the interval to be stopped when i click the button, let it wait X seconds and start again (ofcourse pressing the button again should reset that amount of seconds)
$(document).on('click', '.bgscroller a', function(){
clearInterval(interval);
clearTimeout(timeout);
var timeout = setTimeout(function(){
var interval = setInterval(bgScroll, timeBetweenSwap);
}, delayAfterClick);
});
Now when i click the button a few times the interval goes crazy and stacks up. I would suggest it to be cleared... any advice oh how I should fix this?
Kind regards, Narayan