问题
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