开发者

javascript countdown timer with cookies

开发者 https://www.devze.com 2023-01-03 04:11 出处:网络
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. I got this snippet:

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. 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 t开发者_如何学Pythonhe 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?


Take a look at this SO answer:

javascript-cookie-timeout-with-countdown-timer

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号