倒数计时器与进度条

问题描述:

我正在使用最终倒计时插入。问题是,当我重新加载浏览器的第二个值的开始是与以前相同的时间。例如:时间已经离开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

谢谢.. 请给我看代码的详细信息.. –

好像你在未来一定时间,并希望倒计时。

为什么不这样做是这样的: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)