Countdown Counter Javascript Or Jquery?
I am tryin to create a simple counter that counts backwards from 3 to 0 or 5 to 0 or whatever. It's a timer for a questions so each number needs to be visible to the user. I tried:
Solution 1:
Use setInterval
/clearInterval
instead:
var i = 5;
var t = setInterval(function() {
i === 0 && clearInterval(t);
$(".timerInner").text(i);
i--;
}, 1000);
Solution 2:
Try this,
var i =5;
var timer = setInterval( calltimer, 500);
functioncalltimer(){
$(".timerInner").append( i );
if(i == 0){
clearInterval(timer);
}
i--;
}
Solution 3:
I recommend to use JavaScript method setTimeout
:
function countdown(remainingTime) {
$('.timerInner').text(remainingTime);
if (remainingTime > 0)
setTimeout(function() { countdown(remainingTime - 100); }, 100);
}
countdown(1000);
Fiddle example to play with: http://jsfiddle.net/MSa8h/1/
Solution 4:
uou need to create a loop bassed on setTimeout function, here's a sketch
var i = 3;
var calc = function(){
i--;
if(i==0){
//start new iterationtimeout();
}else{
//end loopreturn;
}
};
var timeout = function(){
setTimeout(calc,1000);
};
Solution 5:
var i =5;
var timer = setInterval( calltimer, 500);
functioncalltimer(){
$(".timerInner").text( i );
if(i == 0){
clearInterval(timer);
}
i--;
}
Thanks for the help
Post a Comment for "Countdown Counter Javascript Or Jquery?"