码迷,mamicode.com
首页 > Web开发 > 详细

js倒计时

时间:2016-08-04 13:19:22      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

/**
* 启动,秒杀倒计时
* totalSecond:剩余秒数
* showTime(tm):回调函数,其中tm={day:"",hour:"",min:"",second:""}
*/
function timer(totalSecond,showTime) {
var secSkillTimeInterval = "";
secSkillTimeInterval = setInterval(function(totalSecond,showTime) {
return function() {
if (totalSecond <= 0) {
clearInterval(secSkillTimeInterval);
}
var tm={
day:parseInt(totalSecond / (60 * 60 * 24)),
hour:parseInt((totalSecond % ( 60 * 60 * 24)) / (60 * 60)),
min:parseInt((totalSecond % (60 * 60)) /60),
second:parseInt(totalSecond %60)
}
showTime(tm);
--totalSecond;
}
}(totalSecond,showTime), 1000);
}
/************调用示例************
//显示秒杀倒计时
timer(60,function(tm){
var msg = tm.day + "天" + tm.hour + "时" + tm.min + "分" + tm.second + "秒";
console.log(msg);
});
********************************/

js倒计时

标签:

原文地址:http://www.cnblogs.com/xiaowei1763369680/p/5736247.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!