jndne jndne - 1 year ago 117
jQuery Question

jQuery Countdown Each Second

I'm trying to make a jQuery countdown type animation, that once it hits 0 it executes a function. However I'm having problems because I'm unsure how to go about doing this. I thought I'd do a while loop then pause for a second until it hits 0. However it doesn't seem possible to pause a while loop. So I'm wondering what's the best way to do this? Thanks.

Answer Source


var counter = 10;
var yourFunc = function(){}
var interval = setInterval(function(){
    if(counter <=0){ yourFunc(); clearInterval(interval); }
}, 1000);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download