下面是编程之家 jb51.cc 通过网络收集整理的代码片段。
编程之家小编现在分享给大家,也给大家做个参考。
/* var countdown = new CountDown( document.getElementById('countdown_wrapper'),new Date(2015,8,27,0) ); countdown.run(); */ var CountDown = function(wrapper,endDate) { // init this.wrapper = wrapper; this.timerRunning = false; this.endDate = endDate; this.template = '{days} DAYS {hours} HOURS {mins} MINS {secs} SECS'; } CountDown.prototype.showtime = function(){ var now = new Date(); var leftTime = this.endDate.getTime() - now.getTime(); var leftsecond = parseInt(leftTime / 1000); var day1 = Math.floor(leftsecond / (60 * 60 * 24)); var hour1 = Math.floor((leftsecond - day1 * 24 * 60 * 60) / 3600); var hour = Math.floor((leftsecond - 60 * 60) / 3600); if (hour < 0) { hour = 0; } if (day1 < 0) { hour = hour1 } var minute = Math.floor((leftsecond - day1 * 24 * 60 * 60 - hour1 * 3600) / 60); var second = Math.floor(leftsecond - day1 * 24 * 60 * 60 - hour1 * 3600 - minute * 60); var html = ''; if (leftTime > 0) { html = this.template; html = html.replace('{days}',day1); html = html.replace('{hours}',hour1); html = html.replace('{mins}',minute); html = html.replace('{secs}',second); this.wrapper.innerHTML = html; } else { html = this.template; html = html.replace('{days}',0); html = html.replace('{hours}',0); html = html.replace('{mins}',0); html = html.replace('{secs}',0); this.wrapper.innerHTML = html; } this.timerRunning = true; } CountDown.prototype.run = function(){ var _this = this; CountDown_timer = setTimeout(function() { _this.showtime(); CountDown_timer = setTimeout(arguments.callee,1000); _this.timerRunning = true; },1000); } CountDown.prototype.stop = function(){ if(timerRunning) clearTimeout(CountDown_timer); this.timerRunning = false; } CountDown.prototype.constructor = CountDown;
以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。