当计时器在 jQuery.countdown 中达到 00 时删除 days/hours/minutes

Remove days/hours/minutes when timer hits 00 in jQuery.countdown

我正在使用 jQuery.countdown 并尝试在计时器达到 00 时使用更新回调函数 .on('update.countdown', function(event) { 删除 days/hours/minutes。所以,几乎工作正常。 但是,只有一个问题。 它在最后一分钟最后一秒结束时 01 秒 停止。所以,它不隐藏。为什么不是 00 秒?

我得到: 01s

应该是:00s

var countdown = $('.countdown[data-countdown-end]');
if (countdown.length > 0) {
    countdown.each(function() {
        var $countdown = $(this),
            finalDate = $countdown.data('countdown-end');
        $countdown.countdown(finalDate)
            .on('update.countdown', function(event) {
              var format = '<span>%-d</span> day%!d '
                  + '<span>%H</span> hr '
                  + '<span>%M</span> min '
                  + '<span>%S</span> sec';
              if(event.offset.totalDays === 0) {
                  format = '<span>%H</span> hr '
                  + '<span>%M</span> min '
                  + '<span>%S</span> sec';
              } 
              if(event.offset.totalHours === 0) {
                  format = 
                  '<span>%M</span> min '
                  + '<span>%S</span> sec';
              }
              if(event.offset.totalMinutes === 0) {
                  format = '<span>%S</span> sec';
              }
              if(event.offset.totalSeconds === 0) {
                  format = '';
              }
            $countdown.html(event.strftime(format));
    }); 
});
}

在没有更新回调函数的情况下工作正常:

如果,我使用了没有更新回调的默认代码。所以,它在最后一分钟的最后一秒结束时停止在 00 秒。

我得到了(很好): 00d 00h 00m 00s

var countdown = $('.countdown[data-countdown-end]');
if (countdown.length > 0) {
    countdown.each(function() {
        var $countdown = $(this),
            finalDate = $countdown.data('countdown-end');
        $countdown.countdown(finalDate, function(event) {
            $countdown.html(event.strftime(
                '%Dd %Hh %Mm %Ss'
            ));
        });
    });
}

为什么更新回调码不是00秒?

我终于从 Advanced example 得到了解决方案。它与 finish 回调函数一起工作正常。

我的代码最终运行如下:

var countdown = $('.countdown[data-countdown-end]');
if (countdown.length > 0) {
    countdown.each(function() {
        var $countdown = $(this),
            finalDate = $countdown.data('countdown-end');
        $countdown.countdown(finalDate)
            .on('update.countdown', function(event) {
              var format = '<span>%-d</span> day%!d '
                  + '<span>%H</span> hr '
                  + '<span>%M</span> min '
                  + '<span>%S</span> sec';
              if(event.offset.totalDays === 0) {
                  format = '<span>%H</span> hr '
                  + '<span>%M</span> min '
                  + '<span>%S</span> sec';
              } 
              if(event.offset.totalHours === 0) {
                  format = 
                  '<span>%M</span> min '
                  + '<span>%S</span> sec';
              }
              if(event.offset.totalMinutes === 0) {
                  format = '<span>%S</span> sec';
              }
            $countdown.html(event.strftime(format));
    })
   .on('finish.countdown', function(event) {
        $countdown.addClass('disabled');
    });
});
}

Css

.countdown.disabled {display:none;}