Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 来自现有倒计时计时器的JS倒计时计时器_Javascript_Jquery_Jquery Plugins_Timelapse - Fatal编程技术网

Javascript 来自现有倒计时计时器的JS倒计时计时器

Javascript 来自现有倒计时计时器的JS倒计时计时器,javascript,jquery,jquery-plugins,timelapse,Javascript,Jquery,Jquery Plugins,Timelapse,我有下面的代码,我想转换此代码,以便它在事件日期后开始向上计数。我可以请求帮助吗 $("#countdown").countdown("2016/02/22", function(event) { var $this = $(this).html(event.strftime('' + '<div class="countdown-col-wrapper col-xs-3"><div class="countdown-col"> <span class="co

我有下面的代码,我想转换此代码,以便它在事件日期后开始向上计数。我可以请求帮助吗

$("#countdown").countdown("2016/02/22", function(event) {
var $this = $(this).html(event.strftime(''
 + '<div class="countdown-col-wrapper col-xs-3"><div class="countdown-col">   <span class="countdown-time"> %-D </span> Days </div></div> '
 + '<div class="countdown-col-wrapper col-xs-3"><div class="countdown-col"><span class="countdown-time"> %H </span> Hours </div></div>'
 + '<div class="countdown-col-wrapper col-xs-3"><div class="countdown-col"><span class="countdown-time"> %M </span> Minutes </div></div>'
 + '<div class="countdown-col-wrapper col-xs-3"><div class="countdown-col"><span class="countdown-time"> %S </span> Seconds </div></div>'));});

第一个代码计算事件的天数。我想完成的是,在事件发生后,计数器开始向上计数。i、 例如,苹果在2016年3月23日发布了它的iphone,倒计时显示还剩1天,然而,在3月23日之后,倒计时开始向上计数,就像发布后的1天一样,以此类推。我在这里找到了一个工作示例:然后修改它以适合您的代码。它们都包含在下面的代码中,因此您可以看到它们是如何工作的。请注意:我无法让它在已经过去的日期下工作。我认为倒计时必须在倒计时结束之前进行。我不认为你能给它一个十年前的日期,让它自动同步;我认为它需要从倒计时开始,然后降到零,然后才能开始计数(至少,我不能让它工作,也许你可以)

另外,如果您在下载倒计时时遇到问题:您需要bower安装倒计时,然后相应地更改下面的src文件。您的bower components文件夹可能与我的文件夹不在同一位置:)


//该站点的示例如下:
var fiveSeconds=new Date().getTime()+5000;
$(“#时钟”)。倒计时(五秒,{elapse:true})
.on('update.countdown',函数(事件){
var$this=$(this);
如果(事件已过){
$this.html(event.strftime('结束后:%H:%M:%S');
}否则{
$this.html(event.strftime('To end:%H:%M:%S');
}
});
//你的例子是:
$(“倒计时”)。倒计时(“2016/12/22”,功能(事件){
如果(事件已过){
$(this.html(event.strftime(“”)
+“%-D天”
+“%H小时”
+“%M分钟”
+“%S秒”);
}否则{
$(this.html(event.strftime(“”)
+“%-D天”
+“%H小时”
+“%M分钟”
+“%S秒”);
}});

欢迎来到StackOverflow!这个倒计时函数是什么?你想得到什么结果?请尝试使用您的代码创建一个事件,以便我们更容易提供帮助。第一个代码计算事件发生的天数。我想完成的是,在事件发生后,计数器开始向上计数。i、 例如,苹果公司于2016年3月23日发布了它的iphone,倒计时显示还剩1天,然而,在3月23日之后,倒计时时间开始向上计数,大约是发布后的1天,以此类推forth@Pranay这回答了你的问题吗?你需要其他帮助吗?我试过你的方法,但是页面不再加载了。我肯定遗漏了什么。@praye什么东西没装?您有什么错误?如果希望以这种方式共享代码,可以将代码放入jsbin中
$('div#clock').countdown(finalDate, {elapse: true})
.on('update.countdown', function(event) {
if (event.elapsed) { // Either true or false
  // Counting up...
} else {
  // Countdown...
}  });
<html>
<head>
  <script src="https://code.jquery.com/jquery-2.1.4.js"></script>
  <script src="../bower_components/jquery.countdown/dist/jquery.countdown.js"></script>
</head>
<body>
  <!-- Example from the site will go here: -->
  <div id="clock" style="height: 150px; width: 150px; background-color: blue"></div>
  <!-- Your example will go here: -->
  <div id="countdown" style="height: 150px; width: 150px; background-color: red"></div>
  <script type="text/javascript">
    // The example from the site:
    var fiveSeconds = new Date().getTime() + 5000;
    $('#clock').countdown(fiveSeconds, {elapse: true})
      .on('update.countdown', function(event) {

        var $this = $(this);
        if (event.elapsed) {
          $this.html(event.strftime('After end: <span>%H:%M:%S</span>'));
        } else {
          $this.html(event.strftime('To end: <span>%H:%M:%S</span>'));
        }
     });

    // Your example:
    $("#countdown").countdown("2016/12/22", function(event) {
        if (event.elapsed) {
          $(this).html(event.strftime(''
     + '<div class="countdown-col-wrapper col-xs-3"><div class="countdown-col"><span class="countdown-time"> %-D </span> Days </div></div> '
     + '<div class="countdown-col-wrapper col-xs-3"><div class="countdown-col"><span class="countdown-time"> %H </span> Hours </div></div>'
     + '<div class="countdown-col-wrapper col-xs-3"><div class="countdown-col"><span class="countdown-time"> %M </span> Minutes </div></div>'
     + '<div class="countdown-col-wrapper col-xs-3"><div class="countdown-col"><span class="countdown-time"> %S </span> Seconds </div></div>'));
        } else {
          $(this).html(event.strftime(''
     + '<div class="countdown-col-wrapper col-xs-3"><div class="countdown-col"><span class="countdown-time"> %-D </span> Days </div></div> '
     + '<div class="countdown-col-wrapper col-xs-3"><div class="countdown-col"><span class="countdown-time"> %H </span> Hours </div></div>'
     + '<div class="countdown-col-wrapper col-xs-3"><div class="countdown-col"><span class="countdown-time"> %M </span> Minutes </div></div>'
     + '<div class="countdown-col-wrapper col-xs-3"><div class="countdown-col"><span class="countdown-time"> %S </span> Seconds </div></div>'));
      }});
  </script>
</body>
</html>