2017-07-03 38 views
0

倒計時腳本,如果我重新加載頁面,重新開始。我需要將它設置到某個日期。倒計時如果我重新加載頁面 - - 需要設置它,直到某個日期

這裏是鏈接,倒數計時器視圖,你也可以下載並使用它或看到代碼:https://timer.craftovdvlp.club/

這裏是腳本:

$(document).ready(function() { 
 

 
    $('#countdown2').ClassyCountdown({ 
 
    end: '1388468325', 
 
    now: '1378441323', 
 
    labels: true, 
 
    style: { 
 
     element: "", 
 
     textResponsive: .5, 
 
     days: { 
 
     gauge: { 
 
      thickness: .01, 
 
      bgColor: "rgba(0,0,0,0.05)", 
 
      fgColor: "#1abc9c" 
 
     }, 
 
     textCSS: 'font-family:\'Open Sans\'; font-size:25px; font-weight:300; color:#34495e;' 
 
     }, 
 
     hours: { 
 
     gauge: { 
 
      thickness: .01, 
 
      bgColor: "rgba(0,0,0,0.05)", 
 
      fgColor: "#2980b9" 
 
     }, 
 
     textCSS: 'font-family:\'Open Sans\'; font-size:25px; font-weight:300; color:#34495e;' 
 
     }, 
 
     minutes: { 
 
     gauge: { 
 
      thickness: .01, 
 
      bgColor: "rgba(0,0,0,0.05)", 
 
      fgColor: "#8e44ad" 
 
     }, 
 
     textCSS: 'font-family:\'Open Sans\'; font-size:25px; font-weight:300; color:#34495e;' 
 
     }, 
 
     seconds: { 
 
     gauge: { 
 
      thickness: .01, 
 
      bgColor: "rgba(0,0,0,0.05)", 
 
      fgColor: "#f39c12" 
 
     }, 
 
     textCSS: 'font-family:\'Open Sans\'; font-size:25px; font-weight:300; color:#34495e;' 
 
     } 
 

 
    }, 
 
    onEndCallback: function() { 
 
     console.log("Time out!"); 
 
    } 
 
    }); 
 

 
});
<link href="http://timer.craftovdvlp.club/css/jquery.classycountdown.css" rel="stylesheet" /> 
 
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" /> 
 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 
 
<script src="http://timer.craftovdvlp.club/js/jquery.classycountdown.js"></script> 
 

 
<script src="http://timer.craftovdvlp.club/js/jquery.knob.js"></script> 
 
<script src="http://timer.craftovdvlp.club/js/jquery.throttle.js"></script> 
 

 
<div class="container"> 
 

 
    <div id="countdown2" class="ClassyCountdownDemo"></div> 
 

 
</div>

附:如果有人有或知道美麗的線循環倒數計時器的鏈接,我將非常感謝幫助)

+2

你是什麼意思 「重新開始」?似乎你已經爲'現在'硬編碼了值 - 如果你想讓倒計時保持相對於你的端點,現在不應該把'no​​w'設置爲...好了...... *現在*?此外,您應該爲此插件託管'.js'文件,並在代碼段中使用「添加外部庫」工具,以便您的問題可以重現。 – Santi

+0

現在我添加了所有包含。是的,我現在在文件** http://timer.craftovdvlp.club/js/jquery.classycountdown.js**,即使我添加日期和寫入格式ON,仍然看不到日期和工作相同或chrashs – Orik3ll0

回答

0

無論何時您重新加載頁面,內存將重置。嘗試使用類似cookie這樣的存儲計時器結束日期的東西。

now也應該在每次重新加載頁面時創建,如@Himanshu Upadhyay的回答和@ Santi的評論中所述。

I.E.

var end = document.cookie.replace(/(?:(?:^|.*;\s*)timerEnd\s*\=\s*([^;]*).*$)|^.*$/, "$1"); 
end = end || '' + Date.now() + 15 * 60 * 1000; // 15 minutes 
document.cookie='timerEnd=' end; 
$('#countdown2').ClassyCountdown({ 
    end: end, 
    now: '' + Date.now(), 
    // ...etc 
+0

感謝您的回覆。定時器崩潰,如果我改變,甚至現在...相同的結束 – Orik3ll0

0

現在獲取當前時間變量是這樣的:

$(document).ready(function() { 
    var d = new Date(); 
    var now = d.getTime(); 

    $('#countdown2').ClassyCountdown({ 
     end: '1388468325', 
     now: now, 
     .... 
    }); 
}); 
+0

或只是'現在:Date.now(),'...... –

+0

謝謝你的答覆。現在應該工作,但工作如何結束?如何從現在開始設置結束日期? – Orik3ll0

+0

一般結束日期將被固定。倒計數的Upto將會消失。 –

相關問題