How can I solve when refresh my page then the flipclock.js coundown clock is reset?

回眸只為那壹抹淺笑 提交于 2019-12-11 16:30:02

问题


When I refresh my page then the the coundown timer is reset. Here is my code:

var clock;

clock = $('.clock').FlipClock({
    clockFace: 'DailyCounter',
    autoStart: false,
    callbacks: {
        stop: function() {
            $('.message').html('The clock has stopped!')
        }
    }
});

clock.setTime(2200880);
clock.setCountdown(true);
clock.start();

回答1:


When you refresh the page, then it is a new page, which means that it reloads the Javascript as if it was the first time the user goes on the page. If you need to keep the counter, you will have to store somewhere (cookie?, server side?) the value of the counter (or probably better the first landing time for the user).




回答2:


I was having the same issue. This helped out a lot. Please see code below.

<script type="text/javascript">
 var clock;
  $(document).ready(function() {
   var currentDate = new Date();
   var futureDate = new Date(2016,11,08,16,15,10); // (yyyy,m,d) //
   var diff = futureDate.getTime() / 1000 - currentDate.getTime() / 1000;
   var clock = $('.clock').FlipClock(diff, {
     clockFace: 'DailyCounter',
     countdown: true
      });
   });
</script>

Source: flipclock.js resets on refresh after time expires



来源:https://stackoverflow.com/questions/30525916/how-can-i-solve-when-refresh-my-page-then-the-flipclock-js-coundown-clock-is-res

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