京东秒杀倒计时案例

京东秒杀倒计时案例

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>京东秒杀</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        body,
        h1,
        h2,
        h3,
        h4,
        h5,
        h6 {
            font-weight: normal;
            font-size: 12px;
        }

        .jd {
            width: 200px;
            height: 300px;
            background-color: #e83632;
            ;
            margin-left: 100px;
            margin-top: 100px;

            text-align: center;
        }

        h2 {
            padding: 15px 0;
            font-size: 36px;
            color: #fff;
        }

        h3 {
            font-size: 20px;
            color: #ccc;

        }

        .title {
            margin-top: 100px;
            color: #fff;
            font-size: 16px;
        }

        .deay {
            margin-top: 30px;
            text-align: center;
            height: 30px;
            line-height: 30px;
        }

        .hours,
        .minute,
        .second {
            display: inline-block;
            width: 30px;
            height: 30px;
            background-color: #000;
            color: #fff;
            font-size: 16px;
        }
    </style>
</head>

<body>
    <div class="jd">
        <h2>京东秒杀</h2>
        <h3>FLASH DEALS</h3>
        <p class="title">距离本场结束还有</p>
        <div class="deay">
            <span class="hours">01</span>
            <span class="minute">20</span>
            <span class="second ">39</span>
        </div>
    </div>
    <script>
        f1()
        setInterval(f1, 1000)
        function f1() {
            // 获取当前时间的毫秒数
            var now = new Date().getTime()

            var t = new Date('2020-12-20 0:0:0').getTime()
            var times = (t - now) / 1000
            // 计算今天距离2020-12-20 的毫秒数
            var h = parseInt(times / 60 / 60 % 24)
            h = h < 10 ? '0' + h : hours
            var m = parseInt(times / 60 % 60); // 分
            m = m < 10 ? '0' + m : m;
            var s = parseInt(times % 60); // 当前的秒
            s = s < 10 ? '0' + s : s;
            document.querySelector('.hours').innerHTML = h
            document.querySelector('.minute').innerHTML = m
            document.querySelector('.second').innerHTML = s
        }
    </script>
</body>

</html>

在这里插入图片描述

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值