倒计时 js
function timeDown(time,dataExecution) {
if(time == -1){
dataExecution();
return;
}
let timeDay = Math.floor(time/60/60/24);
let timeHours = Math.floor((time-timeDay*24*60*60)/60/60);
let timeMunites = Math.floor((time-timeDay*24*60*60-timeHours*60*60)/60);
let timeSeconds = Math.round(time-timeDay*24*60*60-timeHours*60*60-timeMunites*60);
console.log(timeSeconds);
digitSplit(timeDay,$('.J-day-1'),$('.J-day-2'));
digitSplit(timeHours,$('.J-hour-1'),$('.J-hour-2'));
digitSplit(timeMunites,$('.J-minute-1'),$('.J-minute-2'));
digitSplit(timeSeconds,$('.J-second-1'),$('.J-second-2'));
setTimeout(function () {
time--;
timeDown(time,dataExecution);
},1000);
function digitSplit(num,_this1,_this2) {
let singleDigit;
let tenDigit;
if(num > 9){
tenDigit = Math.floor(num/10);
singleDigit = num - tenDigit * 10;
}else{
tenDigit = 0;
singleDigit = num;
}
_this1.text(tenDigit);
_this2.text(singleDigit);
}
}
html
<span class="time J-day-1">0</span><span class="time J-day-2">0</span><span class="word">天</span>
<span class="time J-hour-1">2</span><span class="time J-hour-2">2</span><span class="word">小时</span>
<span class="time J-minute-1">2</span><span class="time J-minute-2">2</span><span class="word">分钟</span>
<span class="time J-second-1">2</span><span class="time J-second-2">2</span><span class="word">秒</span>
引用
倒计时:
timeDown(100000,function(){
alert('啊啊啊');
});