$(function(){
var response = [
{"time":1491656400,"name":"Boss Event","img":"<img style='width:38px;height:38px;' src='http://vignette4.wikia.nocookie.net/tibia/images/f/f4/Hellgorak.gif/revision/latest?cb=20081010165415&path-prefix=en'/>"},
{"time":1491674400,"name":"Paintball Event ","img":"<img style='width:38px;height:38px;' src='http://vignette3.wikia.nocookie.net/tibia/images/3/3d/Snowball.gif/revision/latest?cb=20080124055247&path-prefix=en'/>"}
];
$.each(response, function(i, item, name) {
var time = new Date(item.time*1000) ;
$('#timer').append('<tr><td valign="middle">'+ item.img +'</td><td style="width: 213px;text-align:center;"><strong>'+ item.name +'</strong><br><span id="t'+ i +'"></span></td></tr>');
$('#t'+i).countdown({
until: time,
compact: true,
format: 'HMS'
});
});
});
所以我使用它作为我的胫骨服务器的“事件计时器”,我必须说实话,我不知道这是如何工作的,我只想寻求帮助,我想出如何设置例如3小时,但一旦它达到0就结束了,有没有办法让它重新开始,一旦它倒数到0?
谢谢!
答案 0 :(得分:0)
在没有看到其余代码的情况下,很难看出“响应变量”中的纪元时间戳是否正在终止jquery“.countdown”。如果是这种情况,在倒计时之后,重新声明响应变量并增加时间到纪元时间,然后重新调用该函数。 示例 -
function(){
var time1 = currentTime.getTime()+3*60*60*1000; //time+3hrs
var time2 = currentTime.getTime()+3*60*60*1000; //time+3hrs
//now, declare the new response items
var response = [
{"time":time1,"name":"Boss Event","img":"<img style='width:38px;height:38px;'src='http://vignette4.wikia.nocookie.net/tibia/images/f/f4/Hellgorak.gif/revision/latest?cb=20081010165415&path-prefix=en'/>"},
{"time":time2,"name":"Paintball Event ","img":"<img style='width:38px;height:38px;' src='http://vignette3.wikia.nocookie.net/tibia/images/3/3d/Snowball.gif/revision/latest?cb=20080124055247&path-prefix=en'/>"}
];
$.each(response, function(i, item, name) { //loop through the countdown for each of the response items
var time = new Date(item.time*1000) ;
$('#timer').append('<tr><td valign="middle">'+ item.img +'</td><td style="width: 213px;text-align:center;"><strong>'+ item.name +'</strong><br><span id="t'+ i +'"></span></td></tr>');
$('#t'+i).countdown({
until: time,
compact: true,
format: 'HMS'
}); //end of the countdown
}); //end for each of the response items
//recall the function here
});