Reputation: 329
I know this can't be that difficult, but I swear I can't find a straight forward answer to this. I have the following javascript/jquery function that starts a timer:
function startTimer() { (function ($) {
//timer for the box
window.timer = window.setInterval(function() {
$(".region-brand-window").timer();
}, 10000);
jQuery.fn.timer = function() {
changeBrandOnTimer();
}
})(jQuery); }
How do I stop this thing? And I don't mean pause. I mean turn it off from another function.
Upvotes: 0
Views: 581
Reputation: 23208
call stopTimer whenever you want to stop timer.
function startTimer() { (function ($) {
//timer for the box
window.timer = window.setInterval(function() {
$(".region-brand-window").timer();
}, 10000);
jQuery.fn.timer = function() {
changeBrandOnTimer();
}
})(jQuery); }
function stopTimer(){
clearInterval(timer );
}
Upvotes: 1
Reputation: 5287
To cancel an interval, you would use:
clearInterval(window.timer);
FYI, if it was a timeout you would use clearTimeout()
in the same way.
Upvotes: 2
Reputation: 207501
use window.clearInterval(intervalID)
window.clearInterval(window.timer)
Upvotes: 1