2016-08-02 83 views
-1

我正在使用最終倒計時插入。問題是,當我重新加載瀏覽器的第二個值的開始是與以前相同的時間。例如:時間已經離開12分10秒。 10分鐘後,當我刷新瀏覽器時,分鐘保持不變。我該如何改變它?倒數計時器與進度條

這是我的工作環節 http://rrfpractice.com/662121/mou/final-countdown/

我的腳本是:

$(document).ready(function() { 

    // this code is for countdown 
    $('.countdown').final_countdown({ 
    start: '0', 
    end: ((((31+29+31+30+31+30+31+31+30+31+30+31)*24)*60)*60), 
    now: ((((31+29+31+30+31+30+31+2)*24)*60)*60), 
    seconds: { 
     borderColor: '#2ecc71', 
     borderWidth: '6' 
    }, 
    minutes: { 
     borderColor: '#2ecc71', 
     borderWidth: '6' 
    }, 
    hours: { 
     borderColor: '#2ecc71', 
     borderWidth: '6' 
    }, 
    days: { 
     borderColor: '#2ecc71', 
     borderWidth: '6' 
    }}, function() { 
    // Finish callback 
}); 
+1

確定...你爲什麼做出如此怪異的計算?以這樣的時間戳:'new Date()。getTime()'和你的完成。 – Phil

+0

使用本地存儲,cookie或會話變量來存儲流逝的時間! – Pugazh

+0

謝謝.. 請給我看代碼的詳細信息.. –

回答

0

好像你在未來一定時間,並希望倒計時。

爲什麼不這樣做是這樣的:https://jsfiddle.net/mL1jfsLs/

JS

var start = new Date(); // now 
var end = new Date("12/15/2016"); 

// get total seconds between the times 
var delta = Math.abs(end.getTime() - start.getTime())/1000; 

// calculate (and subtract) whole days 
var days = Math.floor(delta/86400); 
delta -= days * 86400; 

// calculate (and subtract) whole hours 
var hours = Math.floor(delta/3600) % 24; 
delta -= hours * 3600; 

// calculate (and subtract) whole minutes 
var minutes = Math.floor(delta/60) % 60; 
delta -= minutes * 60; 

// what's left is seconds 
var seconds = Math.floor(delta) % 60; // in theory the modulus is not required 

alert("remaining: " + days + "d " + hours + "h " + minutes + "m " + seconds + "s"); 

我不知道你使用的是哪個庫,因爲你沒有說明。但是在你的代碼中有一個參數now,其固定值是你的。所以你需要把它變成一個變量值。
因此,您可以使用new Date()對象獲取當前時間戳,並調用.getTime(),如我的示例中所示。
也許是這樣的:
now: Math.floor((new Date()).getTime()/1000)