I am using the timeTo
jquery library to display a counter and call a function when that counter expires. This happens after 24 hours. When the price is claimed the counter resets to allow another 24 hours. The code is below, but the problem I have is that the counter resets itself when the user logs out:
<div id="countdown-1"></div>
<div class="clock"></div>
<div class="clock"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="jquery.timeTo.js"></script>
<script>
/**
* Set timer countdown in seconds with callback
*/
$('#countdown-1').timeTo(86300, function(){
$('#countdown-1').timeTo('reset');
});
function getRelativeDate(days, hours, minutes){
var date = new Date((new Date()).getTime() + 60000 /* milisec */ * 60 /* minutes */ * 24 /* hours */ * days /* days */);
date.setHours(hours || 0);
date.setMinutes(minutes || 0);
date.setSeconds(0);
return date;
}
</script>
How can I make it always run for every user whether that user is logged in or logged out?
只需将计数器中剩余的当前时间添加到当前时间(以获得结束日期/时间),然后使用AJAX将结束日期/时间存储在数据库中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.