美文网首页
倒计时简约代码

倒计时简约代码

作者: Medicine_8d60 | 来源:发表于2019-04-29 13:44 被阅读0次

    //html
    <em id="countDown"></em>
    //js
    <script>
    var countDown={
    obj:document.getElementById('countDown'),
    timer:null,
    leftTime:8006,
    //将0-9的数字前面加上0,例1变为01
    checkTime:function(i) {
    return i<10?('0'+i):i;
    },
    setTime:function(){
    var that=this;
    that.timer=setInterval(function(){
    if(that.leftTime<=0){
    that.leftTime = 3601;
    }
    that.leftTime--;
    var hours = that.checkTime(parseInt(that.leftTime / 60 / 60)); //计算剩余的小时
    var minutes = that.checkTime(parseInt(that.leftTime / 60 % 60));//计算剩余的分钟
    var seconds = that.checkTime(parseInt(that.leftTime % 60));//计算剩余的秒数
    that.obj.innerHTML=hours+":"+minutes+":"+seconds;
    },1000)
    }
    }
    countDown.setTime();
    </script>

    相关文章

      网友评论

          本文标题:倒计时简约代码

          本文链接:https://www.haomeiwen.com/subject/dwdynqtx.html