js基础应用篇 - 模拟京东倒计时

模拟京东倒计时,按照图示进行布局和效果实现

在这里插入图片描述
在这里插入图片描述

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>倒计时 </title>
    <style>
        li{list-style: none}
      #box{
          color: #fff;
          width: 200px;
          height: 330px;
          background-color: #e83632;
          text-align: center;
          overflow: hidden;
      }
        #box h2{
            font-weight: normal;
            margin-top: 40px;
        }
        #box i{
            display: block;
            width: 40px;
            height: 70px;
            margin: 0 auto;
            background: url(img/seckill.png) no-repeat -65px 0;
        }
        #box p:nth-child(2){
            color: #f19a98;
        }
        #box ul {
            position: absolute;
        }
        #box ul li{
            float: left;
            width: 40px;
            height: 40px;
            line-height: 40px;
            font-weight: bold;
            margin-right: 5px;
            background-color: #2f3430;
        }
        #box .line{
            position: absolute;
            top: 50%;
            width: 130px;
            height: 1px;
            background-color: #e83632;
        }
    </style>
</head>
<body>
<div id="box">
    <h2>倒计时</h2>
    <p>COUNT DOWN</p>
    <i></i>
    <P>距离结束还剩</P>
    <ul id="time">
        <li></li>
        <li></li>
        <li></li>
        <li class="line"></li>
    </ul>
</div>


<script>
    var div = document.getElementById('div2');
    var star = new Date('07 10 2020 00:00:00');
    var lis  = document.getElementsByTagName('li');

    setInterval(function () {
        var now = new Date();
        var c = star-now;

        var s = parseInt(c/1000%60);
        s = toString(s);
        var m = parseInt(c/1000/60%60);
        m = toString(m);
        var h = parseInt(c/1000/60/60);
        h = toString(h);
        lis[0].innerHTML = h;
        lis[1].innerHTML = m;
        lis[2].innerHTML = s;

    },1000);
    
    // 保留2位数,个位数前加0
    function toString(num) {
        num += "";
        if (num.length<2) {
            num = "0"+ num;
        }
        return num;
    }

</script>

</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值