JavaScript 倒计时函数

2019-10-14  本文已影响0人  k_zone
let countTime = 24*60*60*1000    // 一天的时间戳
let time2text = function (t) {
    var s = String(100 + Math.floor(t / 1000) % 60).slice(1)
    var m = String(100 + Math.floor(t / 60000) % 60).slice(1)
    var h = String(100 + Math.floor(t / 3600000)).slice(1)
    console.log(h + ':' + m + ':' + s)
    return h + ':' + m + ':' + s
 }
let countDown = function () {
    console.log(countTime)
    time2text(countTime)
    if (countTime >= 1000) {
        setTimeout(()=>{
            countTime--
            
            countDown()
        }, 1000)
    } else {
        console.log('倒计时结束')
    }
}
countDown()
上一篇 下一篇

猜你喜欢

热点阅读