簡體   English   中英

jQuery倒計時隱藏天/小時/分鍾(如果沒有的話)

[英]jQuery countdown hide days/hours/minutes if none left

我正在使用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);
                    });
                });

謝謝!!

我想您可以為實現這一目標設置一些條件。

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

我不知道插件是否提供某些內置功能來執行此操作,因此我采用了這種方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM