钟表练习

效果图

在这里插入图片描述

代码

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .clock {
            width: 400px;
            height: 400px;
            border-radius: 50%;
            margin: 0 auto;
            margin-top: 100px;
            position: relative;
            background-image: url(./clock.png);
            background-size: contain;
        }

        .sec-wrapper,
        .min-wrapper,
        .hour-wrapper {
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            margin: auto;
        }

        .sec,
        .min,
        .hour {
            position: absolute;
            left: 0;
            right: 0;
            margin: auto;
        }

        .sec-wrapper {
            width: 90%;
            height: 90%;
            /* 设置steps,有每秒钟都停顿的效果 */
            animation: run 60s infinite steps(60);
        }

        .sec {
            width: 2px;
            /* 高度设置为父元素的百分之50 */
            /* 实际上是父元素在转动,但视觉上能出现指针转动的效果 */
            height: 50%;
            background-color: red;
        }

        .min-wrapper {
            width: 70%;
            height: 70%;
            animation: run 3600s infinite;
        }

        .min {
            width: 3px;
            height: 50%;
            background-color: black;
        }

        .hour-wrapper {
            width: 50%;
            height: 50%;
            animation: run 43200s infinite;
        }

        .hour {
            width: 6px;
            height: 50%;
            background-color: black;
        }

        @keyframes run {
            from {
                transform: rotateZ(0deg);
            }

            to {
                transform: rotateZ(360deg);
            }
        }
    </style>
</head>

<body>
    <div class="clock">
        <!-- 秒针 -->
        <div class="sec-wrapper">
            <div class="sec"></div>
        </div>
        <!-- 分针 -->
        <div class="min-wrapper">
            <div class="min"></div>
        </div>
        <!-- 时针 -->
        <div class="hour-wrapper">
            <div class="hour"></div>
        </div>
    </div>
</body>

</html>
发布了90 篇原创文章 · 获赞 0 · 访问量 1829

猜你喜欢

转载自blog.csdn.net/qq_35764106/article/details/104464856