开发者

clearInterval(myTimer); for 60sec

i am trying to clearInterval for 60sec and restart when the 60sec are up j开发者_Python百科query


Ok, so here is a shot in the dark, but lets say you have this code running:

// Will run every 1 second
var myTimer;
function startTimer(){
     myTimer = window.setInterval(function(){
        // Your cool code
     }, 1000); 
};
startTimer();

So, later in your code you could do something like this (I have it arbitrarily attached to a click event, but it could appear anywhere):

$("#pause_timer").click(function(){
    window.clearInterval(myTimer);
    window.setTimeout(function(){
        startTimer();
    }, 60 * 1000); // Wait 60 seconds
});


The clearInterval is just as usual. Then you use a setTimeout to get code to run 60 seconds later, where you start the interval:

window.clearInterval(myTimer);
window.setTimeout(function() {
   myTimer = window.setInterval(timerFunc, intervalMilliseconds);
}, 60000);

Note: This is just plain Javascript and has nothing to do with jQuery.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜