javascript
  • countdown
  • repeat
  • 2017-04-08 66 views 0 likes 
    0
    $(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' 
         }); 
        }); 
    }); 
    

    這樣的IM以此作爲「事件計時器」我的脛骨服務器,我必須說實話,我不知道這是如何工作的,我只是想尋求幫助,我想出瞭如何設置例如3個小時,但一旦它達到0它只是結束,有沒有辦法讓它重新啓動一次倒計時到0?讓這個倒計時重啓

    謝謝!

    回答

    0

    沒有看到代碼的其餘部分,很難判斷「響應變量」中的epoch時間戳是否終止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 
        }); 
    
    相關問題