计时器动画

计时器动画

视频效果

计时器

css样式

 <style>
        * {
            padding: 0;
            margin: 0;
        }

        .whole {
            width: 300px;
            height: 500px;
            background-color: aqua;
            margin: auto;
            padding-top: 1px;
        }

        #top {
            width: 200px;
            height: 50px;
            margin: 20px auto;
            text-align: center;
            font-size: 30px;
        }

        #bottom {
            width: 200px;
            height: 400px;
            list-style: none;
            margin: auto;
        }

        button {
            width: 200px;
            height: 50px;
            margin: 50px 0px 0px 50px;
            line-height: 50px;
            background-color: chocolate;
        }
    </style>

html部分

<div class="whole">
        <div id="top">
            <span id="span_1">00</span>
            <span id="span_2">00</span>
            <span id="span_3">00</span>
        </div>
        <button id="start">开始</button>
        <button id="stop">暂停</button>
        <button id="over">结束</button>
    </div>

js部分

//函数封装名字
function name(id){
 return document.getElementById(id)
}
//补零函数
 function zero(time) {
        return time >= 10 ? time : "0" + time
    }
//开始按钮
 name("start").onclick = function () {
        this.disabled = true
        name("stop").disabled = false
        name("over").disabled = false

        time = setInterval(function () {
            num++
            name("span_3").innerHTML = zero(parseInt(num % 60)) //zero是补零函数名
            name("span_2").innerHTML = zero(parseInt(num / 60 % 60))
            name("span_1").innerHTML = zero(parseInt(num / 60 / 60 % 24))

        }, 100)
    }
    // 停止按钮
  name("stop").onclick = function () {
        this.disabled = true
        name("start").disabled = false
        clearInterval(time)
    }
    // 清除按钮
     name("over").onclick = function () {
        this.disabled = true
        name("start").disabled = false
        clearInterval(time)
        num = 0
        name("span_3").innerHTML = zero(parseInt(num % 60))
        name("span_2").innerHTML = zero(parseInt(num / 60 % 60))
        name("span_1").innerHTML = zero(parseInt(num / 60 / 60 % 24))
    }
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值