手写数字时钟源码

手写数字时钟源码
<!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>clock</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        html,body{
            height: 100%;
        }

        body {
            display: grid;
            place-items: center;
        }
        .clock {
            display: flex;
            align-items: center;
            justify-content: center;
            background:#dde1e7;
            width: 250px;
            height: 250px;
            border-radius: 50%;
            box-shadow: -3px -3px 7px #ffffff73,
            3px 3px 5px rgba(94, 104, 121, 0.288);
        }
        .clock::before {
            position: absolute;
            content: '';
            height: 220px;
            width: 220px;
            background: #dde1e7;
            border-radius: 50%;
            box-shadow: inset -3px -3px 7px #ffffff73,
                        inset 3px 3px 5px rgba(94, 104, 121, 0.288);
        }
        .clock::after {
            position: absolute;
            content: '';
            height: 120px;
            width: 120px;
            background: #dde1e7;
            border-radius: 50%;
            box-shadow: -1px -1px 5px #ffffff73,
                        1px 1px 3px rgba(94, 104, 121, 0.288);
        }
        .clock .center-nut {
            height: 15px;
            width: 15px;
            background: #404040;
            border-radius: 50%;
            z-index: 2;
            position: absolute;
        }
        .clock .center-nut2 {
            height: 9px;
            width: 9px;
            background: #3498db;
            border-radius: 50%;
            z-index: 15;
            position: absolute;
        }
        .indicators div {
            position: absolute;
            width: 2px;
            height: 5px;
            background: #404040;
        }
        .indicators div:nth-child(1) {
            transform:rotate(30deg) translateY(-100px);
        }
        .indicators div:nth-child(2) {
            transform:rotate(60deg) translateY(-100px);
        }
        .indicators div:nth-child(3) {
            transform:rotate(90deg) translateY(-100px);
            background: #3498db;
        }
        .indicators div:nth-child(4) {
            transform:rotate(120deg) translateY(-100px);
        }
        .indicators div:nth-child(5) {
            transform:rotate(150deg) translateY(-100px);
        }
        .indicators div:nth-child(6) {
            transform:rotate(180deg) translateY(-100px);
            background: #3498db;
        }
        .indicators div:nth-child(7) {
            transform:rotate(210deg) translateY(-100px);
        }
        .indicators div:nth-child(8) {
            transform:rotate(240deg) translateY(-100px);
        }
        .indicators div:nth-child(9) {
            transform:rotate(270deg) translateY(-100px);
            background: #3498db;
        }
        .indicators div:nth-child(10) {
            transform:rotate(300deg) translateY(-100px);
        }
        .indicators div:nth-child(11) {
            transform:rotate(330deg) translateY(-100px);
        }
        .indicators div:nth-child(12) {
            transform:rotate(360deg) translateY(-100px);
            background: #3498db;
        }
        .sec-hand, .min-hand, .hr-hand{
            position: absolute;
        }
        .sec-hand, .sec {
            height: 180px;
            width: 180px;
            z-index: 6;
            /* background: rgb(241, 16, 16); */
        }
        .min-hand, .min {
            height: 140px;
            width: 140px;
            z-index: 5;
        }
        .hr-hand, .hr {
            height: 110px;
            width: 110px;
            z-index: 4;
        }
        .sec, .min, .hr {
            display: flex;
            /* align-items: center; */
            position: absolute;
            justify-content: center;
        }
        .sec:before {
            position: absolute;
            content: '';
            height: 110px;
            width: 3px;
            background: #3498db;
        }
        .sec:after {
            position: absolute;
            content: '';
            height: 35px;
            width: 7px;
            background: #3498db;
            top: 105px;
            border-radius: 5px;
        }
        .min:before {
            position: absolute;
            content: '';
            top: -15px;
            width: 1px;
            border-left: 3px solid transparent;
            border-right: 3px solid transparent;
            border-bottom: 60px solid #e95945;
        }
        .min:after {
            position: absolute;
            content: '';
            top: 40px;
            width: 3px;
            border-left: 3px solid transparent;
            border-right: 3px solid transparent;
            border-bottom: 30px solid #e95945;
        }
        .hr:before {
            position: absolute;
            content: '';
            /* top: -15px; */
            width: 1px;
            border-left: 3px solid transparent;
            border-right: 3px solid transparent;
            border-bottom: 35px solid #303030;
        }
        .hr:after {
            position: absolute;
            content: '';
            top: 35px;
            width: 3px;
            border-left: 3px solid transparent;
            border-right: 3px solid transparent;
            border-bottom: 35px solid #303030;
        }
    </style>
</head>
<body>
    <div class="clock">
        <div class="center-nut"></div>
        <div class="center-nut2"></div>
        <div class="indicators">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
        <div class="sec-hand">
            <div class="sec"></div>
        </div>
        <div class="min-hand">
            <div class="min"></div>
        </div>
        <div class="hr-hand">
            <div class="hr"></div>
        </div>
    </div>

    <script>
        const sec = document.querySelector(".sec");
        const min = document.querySelector(".min");
        const hr = document.querySelector(".hr");

        setInterval(() => {
            let time = new Date();
            let secs = time.getSeconds() * 6;
            let mins = time.getMinutes() * 6;
            let hrs = time.getHours() * 30;
            sec.style.transform = `rotateZ(${secs}deg)`;
            min.style.transform = `rotateZ(${mins}deg)`;
            hr.style.transform = `rotateZ(${hrs + (mins/12)}deg)`;
        }, 1000); //默认一秒
    </script>
</body>
</html>
素材来自于油管。手打不易,且看且学会。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值