Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a countdown from timer

Is there any way to make a countdown with 60 seconds... Here is the code for timer:

var count = 0;
var timer = $.timer(function() {
    $('#counter').html(++count);
});
timer.set({ time : 1000, autostart : true });

What I need to chabge to make this code like countdown> THANKS

like image 545
Peter Web Avatar asked Dec 09 '22 00:12

Peter Web


1 Answers

Counts from 0 to 60.

var count = 0, timer = setInterval(function() {
    $("#counter").html((count++)+1);
    if(count == 59) clearInterval(timer);
}, 1000);

Or from 60 to 0:

var count = 60, timer = setInterval(function() {
    $("#counter").html(count--);
    if(count == 1) clearInterval(timer);
}, 1000);
like image 166
Elliot Bonneville Avatar answered Dec 11 '22 13:12

Elliot Bonneville