[英]javascript countdown timer with cookies
I have a countdown timer that will show a target amount to be fundraised like USD1000000 and slowly count backwards to zero over a period of days. 我有一个倒数计时器,它将显示要筹集的目标金额,例如USD1000000,并在几天内慢慢倒数至零。 I got this snippet: 我得到了以下片段:
$(function()
{
var cnt = 75000000;
var count = setInterval(function()
{
if (cnt > 0)
{
$('#target').html("<span>KSHS</span><strong>" + cnt + " Target </strong>");
cnt--;
}
else
{
clearInterval(count);
$('#target').html("<strong> Target Achieved! </strong>");
}
}, 4000);
});
The only problem is that everytime you refresh the page the counter starts again which essentially means it will never end. 唯一的问题是,每次刷新页面时,计数器都会再次启动,这实际上意味着它将永远不会结束。
I'd like it that a when a user revisits/refreshes the page the counter persists and continues. 我希望当用户重新访问/刷新页面时,计数器将继续存在并继续。 I've read that javascript cookies can be used for this, just don't know how to implement them, any help? 我读过javascript cookie可以用于此目的,只是不知道如何实现它们,有帮助吗?
Take a look at this SO answer: 看看这个SO答案:
javascript-cookie-timeout-with-countdown-timer javascript-cookie-timeout-with-countdown-timer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.