问题
http://flipclockjs.com/
I need a counter which counts down to zero from a certain time (for example 2 hours). After those two hours the timer needs to reset and starts again.
How can I do this? I can't find anything about it in their docs.
What I got now:
var clock = $('.your-clock').FlipClock({
countdown : true,
});
回答1:
Try this one:
var clock = $('.your-clock').FlipClock({
countdown : true,
});
clock.setTime(10);
clock.start();
setTimeout(function(){
checktime();
}, 1000);
function checktime(){
t = clock.getTime();
if(t<=0){
clock.setTime(10);
clock.start();
}
setTimeout(function(){
checktime();
}, 1000);
}
回答2:
You can use method, see 'Chainable Methods' example.
clock.start(function() {
setInterval(function() {
clock.stop().reset().start();
}, 7200);
});
回答3:
I assume that you want to decrease every second? this is a non jquery way:
var counter, myInterval;
function createCountDown(startHourInSecond){
counter = startHourInSecond;
myInterval =window.setInterval(function(){
counter --;
if (counter ==0){
clearInterval(myInterval);
counter = startHourInSecond;
createCountDown(counter);
}
}, 1000);
}
createCountDown(7200);
来源:https://stackoverflow.com/questions/42764684/countdown-flipclock-and-reset-after-counting-to-zero