jndne jndne - 5 months ago 39
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.



var counter = 10;
var yourFunc = function(){}
var interval = setInterval(function(){
    if(counter <=0){ yourFunc(); clearInterval(interval); }
}, 1000);