JS+HTML>时钟

10 篇文章 0 订阅
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>时钟</title>
    <!-- <link rel="stylesheet" href="./index.css"> -->
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        section {
            width: 500px;
            height: 500px;
            margin: 50px auto;
            background-color: black;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        section .box {
            width: 400px;
            height: 400px;
            border: 10px solid #fff;
            border-radius: 50%;
            background-color: antiquewhite;
            position: relative;
            box-shadow: inset 0px 0px 25px rgb(115, 112, 112);
            text-align: center;
        }

        section .box div {
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            margin: auto;
            /* 设置原点 */
            transform-origin: center bottom;
        }

        span {
            font-size: 22px;
            position: absolute;
            height: 100%;
            left: 0;
            right: 0;
            margin: auto;
            padding: 10px;
        }

        span i:nth-of-type(1) {
            display: inline-block;
        }

        .center {
            bottom: 0;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: rgb(0, 0, 0);
            z-index: 999;
        }

        .shi {
            width: 10px;
            height: 80px;
            background-color: rgb(252, 12, 12);
            bottom: 80px;
            border-radius: 5px;
        }

        .fen {
            width: 10px;
            height: 100px;
            background-color: rgb(13, 0, 254);
            bottom: 100px;
            border-radius: 5px;

        }

        .miao {
            width: 10px;
            bottom: 120px;
            height: 120px;
            background-color: rgb(198, 255, 9);
            border-radius: 5px;
        }
    </style>
</head>

<body>
    <section>
        <div class="box">
            <span><i> 1 </i></span>
            <span><i> 2 </i></span>
            <span><i> 3 </i></span>
            <span><i> 4 </i></span>
            <span><i> 5 </i></span>
            <span><i> 6 </i></span>
            <span><i> 7 </i></span>
            <span><i> 8 </i></span>
            <span><i> 9 </i></span>
            <span><i> 10</i></span>
            <span><i> 11</i></span>
            <span><i> 12</i></span>

            <div class="center"></div>
            <div class="shi"></div>
            <div class="fen"></div>
            <div class="miao"></div>
        </div>


    </section>
</body>

<!-- <script src="./index.js"></script> -->
<script>
    var span = document.querySelectorAll('.box span');
    var is = document.querySelectorAll('.box span i');
    console.log(i);
    for (var i = 0; i < span.length; i++) {
        span[i].style.transform = `rotate(${(i + 1) * 30}deg)`;
        is[i].style.transform = `rotate(${-(i + 1) * 30}deg)`;
    }

    var shi = document.querySelector('.shi');
    var fen = document.querySelector('.fen');
    var miao = document.querySelector('.miao');


    function Time() {
        this.ho = function (h) {
            shi.style.transform = `rotate(${(h * 30)}deg)`
        }
        this.mi = function (f) {
            fen.style.transform = `rotate(${(f * 6)}deg)`

        }
        this.se = function (m) {
            miao.style.transform = `rotate(${(m * 6)}deg)`
        }
    }

    function move() {
        var date = new Date();
        //秒
        var s = date.getSeconds();
        //分
        var f = date.getMinutes() + s / 60;
        //时
        var h = date.getHours() + f / 60;
        //实例化构造函数
        var time = new Time();
        time.ho(h);
        time.mi(f);
        time.se(s);
    }
    move();
    //计时函数
    setInterval(move, 1000);

</script>

</html>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值