Countdown flipclock and reset after counting to zero

寵の児 提交于 2019-12-24 09:47:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!