多个倒计时
Posted 明天后浪
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了多个倒计时相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ment</title>
<script src="time.js"></script>
</head>
<body>
<div id="countdown"></div>
<script>// 引用倒计时
countdown({
‘end‘:[‘2016/6/27 23:18:00‘ , ‘2016/6/30 24:00:00‘ , ‘2016/7/01 24:00:00‘],
‘callback‘:function () {
document.getElementById(‘countdown‘).innerHTML = ‘the end!‘;
// $(‘.login_award_time‘).remove();
}
});
</script>
</body>
</html>
(function (){
function countdown(config){
var startDate = config.start ? new Date(config.start) : new Date();
for(var i=0;i<config.end.length;i++){
var num =(new Date(config.end[i]) - startDate )/1000;
console.log(num)
if (num > 0){
config.endtime = config.end[i];
console.log(‘config.endtime‘,config.endtime)
break;
}
}
var endDate = new Date(config.endtime);
var id = config.id || ‘countdown‘;
var time = (endDate - startDate)/1000;
// console.log(time)
if(time < 0){
if(config.callback){
config.callback();
}
return;
}
var day = parseInt(time/86400, 10);
var hour = parseInt(time%86400/60/60, 10);
var minute = parseInt(time%86400%3600/60, 10);
var second = parseInt(time%86400%3600%60, 10);
var mayday = day > 0?day+‘天‘:‘‘;
var mayhour = hour<10?‘0‘+hour:hour;
var mayminute = minute<10?‘0‘+minute : minute;
var maysecond = second<10?‘0‘+second : second;
setTimeout(function (){
document.getElementById(id).innerHTML = mayday+mayhour+‘:‘+mayminute+‘:‘+maysecond;
countdown(config);
}, 1000);
}
window.countdown = countdown;
})();
以上是关于多个倒计时的主要内容,如果未能解决你的问题,请参考以下文章