【问题标题】:jQuery countdown hide days/hours/minutes if none leftjQuery倒计时隐藏天/小时/分钟,如果没有剩下
【发布时间】:2016-04-06 02:30:14
【问题描述】:

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

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

此时它会显示类似..

00 天 00 小时 13 分 58 秒

我想像这样显示它..

13 分 58 秒

HTML

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

脚本

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);
                    });
                });

谢谢!!

【问题讨论】:

    标签: javascript jquery countdown


    【解决方案1】:

    我想你可以设置一些条件来实现这一点。

    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);
       });
    });
    

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

    【讨论】:

    • 我很高兴它有帮助:)
    猜你喜欢
    • 2020-08-22
    • 1970-01-01
    • 2014-10-26
    • 2017-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-24
    相关资源
    最近更新 更多