2016-12-06 152 views
0

我想设置倒计时到1月1日2017年。但刷新页面时,倒计时复位,并开始24天后再次计数23小时50分钟.. check the image时间重置jQuery的优雅倒计时刷新页面时

$(document).ready(function() { 
 
     $('#countdown4').ClassyCountdown({ 
 
      end: $.now() + 2160000, 
 
      labels: true, 
 
      style: { 
 
       element: "", 
 
       textResponsive: .5, 
 
       days: { 
 
        gauge: { 
 
         thickness: .03, 
 
         bgColor: "rgba(255,255,255,0.05)", 
 
         fgColor: "#1abc9c" 
 
        }, 
 
        textCSS: 'font-family:\'Open Sans\'; font-size:25px; font-weight:300; color:#fff;' 
 
       }, 
 
       hours: { 
 
        gauge: { 
 
         thickness: .03, 
 
         bgColor: "rgba(255,255,255,0.05)", 
 
         fgColor: "#2980b9" 
 
        }, 
 
        textCSS: 'font-family:\'Open Sans\'; font-size:25px; font-weight:300; color:#fff;' 
 
       }, 
 
       minutes: { 
 
        gauge: { 
 
         thickness: .03, 
 
         bgColor: "rgba(255,255,255,0.05)", 
 
         fgColor: "#8e44ad" 
 
        }, 
 
        textCSS: 'font-family:\'Open Sans\'; font-size:25px; font-weight:300; color:#fff;' 
 
       }, 
 
       seconds: { 
 
        gauge: { 
 
         thickness: .03, 
 
         bgColor: "rgba(255,255,255,0.05)", 
 
         fgColor: "#f39c12" 
 
        }, 
 
        textCSS: 'font-family:\'Open Sans\'; font-size:25px; font-weight:300; color:#fff;' 
 
       } 
 

 
      }, 
 
      onEndCallback: function() { 
 
       console.log("Time out!"); 
 
      } 
 
     }); 
 

 
    }); 
 

检查代码中,我使用

+0

,你可以分享你什么尝试? –

+2

我不知道你想要什么。你为什么要倒数到2016年1月1日 - 这是过去。你的结局总是从现在起25天:end:$ .now()+ 2160000 - 请告诉我们,你到底想要什么。 – Seb

+0

对不起,coutdown日期是2017年1月1日 –

回答

1

您可以使用JavaScript方法SetInterval()用于创建倒计时。它每秒钟计数一次(1000毫秒)。

此示例显示了如何计算时间结束一年

$(function(){ 
    setInterval(function(){ 
     date_future = new Date(new Date().getFullYear() +1, 0, 1); 
     date_now = new Date(); 

     seconds = Math.floor((date_future - (date_now))/1000); 
     minutes = Math.floor(seconds/60); 
     hours = Math.floor(minutes/60); 
     days = Math.floor(hours/24); 

     hours = hours-(days*24); 
     minutes = minutes-(days*24*60)-(hours*60); 
     seconds = seconds-(days*24*60*60)-(hours*60*60)-(minutes*60); 

     $("#timeDay").text(days); 
     $("#timeHours").text(hours); 
     $("#timeMinutes").text(minutes); 
     $("#timeSeconds").text(seconds); 
    },1000); 
}); 
+0

帮了我很多 –

+0

@JIBINBJ你可以接受,如果帮助。 –