停止在页面刷新时重置jQuery倒计时?

时间:2020-09-02 08:39:16

标签: jquery

我发现了this个很棒的插件,但不幸的是,作者不再提供支持。我知道我没有太大帮助,我不是js专业人士,但是有什么办法可以在每次页面刷新时停止倒计时重置吗?谢谢您的任何帮助。

编辑:停止,我的意思是运行一次,直到到期,或者直到我单击停止或刷新按钮为止,每个人的剩余持续时间都相同,就像使用格式 dateAndTime:“ 2022/01/01 00:00:00“

jsfiddle demo

<div id="clock"></div>

$(function(){
   $("#clock").countdowntimer({
      size : "lg",
      hours : 24,
      minutes : 10,
      displayFormat : "DHMS",
      labelsFormat : true
   });
});

1 个答案:

答案 0 :(得分:0)

要在页面刷新时保留倒计时值,您需要使用dateAndTime属性,以便针对静态日期计算倒计时,而不是将 current 日期。试试这个:

jQuery($ => {
  $("#clock").countdowntimer({
    size: "lg",
    dateAndTime : "2020/09/03 12:00:00",
    displayFormat: "DHMS",
    labelsFormat: true
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/harshen/jQuery-countdownTimer/master/dist/js/jQuery.countdownTimer.min.js"></script>
<link rel="stylesheet" href="https://cdn.rawgit.com/harshen/jQuery-countdownTimer/master/dist/css/jQuery.countdownTimer.css" />
<div id="clock"></div>