如果没有,jQuery倒计时会隐藏天/小时/分钟

时间:2016-04-06 02:30:14

标签: javascript jquery countdown

我正在使用The Final Countdown jQuery脚本.. http://hilios.github.io/jQuery.countdown/

我想隐藏天,分钟等,如果没有剩余(即达到0)。

此时它会显示类似......

<00> 00天00小时13分58秒

我希望将其显示为..

13分58秒

HTML

<span id="clock-{{ $game->id }}"></span>

SCRIPT

var endGame = moment.tz("{{ $game->updated_at->addDays(3) }}", "Europe/Volgograd");

                $('#clock-{{ $game->id }}').countdown(endGame.toDate(), function(event) {
                    $(this).html(event.strftime('%-D days %-H hours %-M min %-S sec')).on('finish.countdown', function(event){
                        $(this).html(event.strftime('This Game has Ended.'));
                        $('.clock-{{ $game->id }}').fadeOut(2000);
                    });
                });

谢谢!

1 个答案:

答案 0 :(得分:0)

我想你可以为实现这个目的提出一些条件。

var endGame = moment.tz("{{ $game->updated_at->addDays(3) }}", "Europe/Volgograd");

$('#clock-{{ $game->id }}').countdown(endGame.toDate(), function(event) {
   var str = "";
   // if 0 number of days, show H:M:S
   if(parseInt(event.strftime('%D')) == 0) {
       str = event.strftime('%-H hours %-M min %-S sec');
       // if 0 days 0 hours, show M:S
       if(parseInt(event.strftime('%H')) == 0) {
          str = event.strftime('%-M min %-S sec');
          // if 0 days 0 hours 0 minutes, show only Seconds
          if(parseInt(event.strftime('%M')) == 0) {
             str = event.strftime('%-S sec');
          }
       }
   } else {
       str = event.strftime('%-D days %-H hours %-M min %-S sec');
   }
   $(this).html(str).on('finish.countdown', function(event){
      $(this).html(event.strftime('This Game has Ended.'));
      $('.clock-{{ $game->id }}').fadeOut(2000);
   });
});

我不知道这个插件是否提供了一些内置功能,所以我采用了这种方法。

相关问题