jQuery毫秒倒计时

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8">
        <meta name="author" content="https://my.oschina.net/u/3010603/blog" />
        <title>jQuery毫秒倒计时</title>
        <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

        <script type="text/javascript">
            $(document).ready(function() {
                var times = 60 * 100; // 60秒  6000毫秒
                countTime = setInterval(function() { //
                    times = --times < 0 ? 0 : times;

                    var ms = Math.floor(times / 100).toString(); //把times除以100取整数,转换为字符字符串

                    if(ms.length <= 1) {
                        ms = "0" + ms;
                    }
                    var hm = Math.floor(times % 100).toString(); //把time的百分比取小数点后面的两位数转换为字符字符串
                    if(hm.length <= 1) {
                        hm = "0" + hm;
                    }
                    if(times == 0) {
                        $("#_txt").html("倒计时结束");
                        clearInterval(countTime);
                    }
                    // 获取分钟、毫秒数
                    $(".a").html(ms);
                    $(".b").html(hm);
                }, 10);
            });
        </script>
        <style>
            .warp {
                width: 100%;
                height: 100px;
                line-height: 100px;
                text-align: center;
                font-size: 40px;

            }
            
            .warp strong {
                width: 100px;
                display: inline-block;
                text-align: center;
                font-family: georgia;
                color: #C9302C;
            }
        </style>
    </head>

    <body>
        <div class="warp">
            <strong class="a">60</strong>秒 <strong class="b"></strong>毫秒
        </div>

        <div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">

            <div id="_txt"></div>
        </div>
    </body>

</html>

效果:222829_P9ts_3010603.png

转载于:https://my.oschina.net/u/3010603/blog/795703

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值