用js写京东秒杀倒计时

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 190px;
            height: 260px;
            background: url(./4a15d8883775742e3efbb850ae14def7.png);
        }

        h2 {
            color: white;
            text-align: center;
            line-height: 100px;
            height: 100px;
            font-size: 30px;
            margin-bottom: 50px;
        }

        p {
            color: white;
        }

    span {
            display: inline-block;
            width: 40px;
            height: 40px;
            background-color: black;
            font-size: 30px;
        }

        p {
            text-align: center;
       

        }

   
        strong{
       
            line-height: 40px;
            font-weight: 900;
            font-size: 30px;
        }
        a{
            text-decoration: none;
            font-size: 20px;
            color: white;
            font-weight: 600;
        }
      
    </style>
</head>

<body>
    <div>
        <h2>京东秒杀</h2>
        <p><a href="">18:00</a>点场 距结束</p>
        <p><span class="hour"></span>
            <strong>:</strong>
             <span class="minute"></span>
             <strong>: </strong>
             <span class="second"></span></p>

    </div>
    <script>
        const clock = document.querySelector('.countdown.clock')
        const hour = document.querySelector('.hour')
        const minutes = document.querySelector('.minute')
        const second = document.querySelector('.second')
        let inputTime = +new Date('2023-11-18 18:00:00')
        countDown()
        setInterval(countDown, 1000)

        function countDown() {
            let nowTime = +new Date()
            let times = (inputTime - nowTime) / 1000
            let h = parseInt(times / 60 / 60 % 24);//时
            h = h < 10 ? '0' + h : h;
            hour.innerHTML = h;
            let m = parseInt(times / 60 % 60);//分
            m = m < 10 ? '0' + m : m;
            minutes.innerHTML = m;
            let s = parseInt(times % 60);//秒
            s = s < 10 ? '0' + s : s;
            second.innerHTML = s;

        }
    </script>
</body>

</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值