倒计时 js

倒计时 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('啊啊啊');
});
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值