2016-10-21 94 views
-2

我想以小時顯示倒計時:分鐘:關閉時間(如果打開)或開放時間(關閉第二天)時的秒數。我怎樣才能在HTML中做到這一點?顯示倒計時到當天結束時間/第二天開放時間

+0

如果打開或關閉了什麼?請更具體一些,請嘗試編寫一些代碼。 –

+0

您需要JavaScript才能做到這一點,而不是html,hth –

+0

從星期一至星期六10:00至19:00營業。週日關閉。我想在網站上爲訪問者實現一個倒數計數器。例如。我們*打開*爲另一* 2:27:30 *(如果打開)或我們*關閉,並將打開* * 2:27:30 *(如果關閉) – Joeyk

回答

0
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>countdown</title> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-countdown/2.0.2/jquery.plugin.min.js"></script> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-countdown/2.0.2/jquery.countdown.min.js"></script> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script> 
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-countdown/2.0.2/jquery.countdown.css" /> 
    <style type="text/css"> 
     #countdownText span 
     { 
      display: none; 
     } 
     #countdownText.opened .close, #countdownText.closed .open 
     { 
      display: inline; 
     } 
    </style> 
    <script type="text/javascript"> 
     $(function() { 
      var $timer = $('#timer'); 
      var $countdownText = $('#countdownText'); 
      var now = moment(); 
      var openingToday = moment({hour: 8}); 
      var closingTime = moment({ hour: 17}); 
      var openingTime = moment({ year: now.year(), month: now.month(), date: now.date() + 1, hour: 8 }); 
      if(now.diff(openingToday) < 0) 
      { 
       $timer.countdown({ 
        until: openingToday._d 
       }); 
       $countdownText.addClass('closed'); 
      } 
      else if (now.diff(closingTime) < 0) 
      { 
       $timer.countdown({ 
        until: closingTime._d 
       }); 
       $countdownText.addClass('opened'); 
      } 
      else 
      { 
       $timer.countdown({ 
        until: openingTime._d 
       }); 
       $countdownText.addClass('closed'); 
      } 
     }); 
    </script> 
</head> 
<body> 
    <div id="countdownText"> 
     <span class="open">Opening in</span> 
     <span class="close">Closing in</span> 
    </div> 
    <div id="timer"></div> 
</body> 
</html> 
相關問題