标签:
/**
* 启动,秒杀倒计时
* 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);
});
********************************/
标签:
原文地址:http://www.cnblogs.com/xiaowei1763369680/p/5736247.html