1

我使用翻转时钟 JS 进行计数,但是当我重新加载页面时间从零开始时,我怎么能像这样节省时间

var clock;      
 $(document).ready(function() {
  clock = $('.clock').FlipClock({
   clockFace: 'DailyCounter'
 });
});
4

1 回答 1

2

这是一种可能的解决方案:考虑到它不会在月底重置天数。但是,如果您愿意,可以将其设置为“autoStart: false”和“setInterval”...

$(document).ready(function() {
  var date = new Date(),
      days = date.getDate()*60*60*24,
      hours = date.getHours()*60*60,
      minutes = date.getMinutes()*60,
      sec = date.getSeconds(),
      clock = $('.clock').FlipClock({
    clockFace: 'DailyCounter'
  });  
  clock.setTime(days+hours+minutes+sec);
});
<!DOCTYPE html>
<html>
	<head>
		<link rel="stylesheet" href="http://flipclockjs.com/_themes/flipclockjs/css/flipclock.css">
	</head>
	<body>
		<div class="clock"></div>
		<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
		<script src="http://flipclockjs.com/_themes/flipclockjs/js/flipclock/flipclock.js"></script>
	</body>
</html>

操场

于 2014-12-27T16:26:54.670 回答