CSS/HTML制作网页中动态时钟解析

37 篇文章 8 订阅

简介:
该案例中旋转的并非是指针,而是将背景设置为透明色的指针父元素。
对于实现钟表效果,只需要将指针父元素块在clock中居中,然后指针在其父元素中居中,让指针父元素旋转即可。

效果图:
在这里插入图片描述
背景:
在这里插入图片描述
源码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>时钟</title>
    <link rel="stylesheet" href="../02CSS/reset.css">
    <style>
        .clock,.clock > div{
            position: absolute;
            left: 0px;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;
        }
        .clock{
            width: 700px;
            height: 700px;
            background-image: url("img/13/bg.png");
            background-size: cover;
            overflow: hidden;
        }
            
        .clock .sec-wrapper{
            width: 600px;
            height: 600px;
           animation: run 60s infinite steps(60);
        }
        .clock .sec-wrapper .sec{
            width: 10px;
            height: 280px;
            margin: 0px auto;
            margin-top: 20px;
            background-color: black;
        }
        

        .clock .mine-wrapper{
            width: 500px;
            height: 500px;
            animation: run 3600s steps(60) infinite;
        }
        .clock .mine-wrapper .mine{
            width: 10px;
            height: 230px;
            margin: 0px auto;
            margin-top: 20px;
            background-color: rgb(90, 90, 90);
           
        }
        .clock .hour-wrapper{
            width: 400px;
            height: 400px;
            animation: run 216000s steps(60) infinite;
        }
        .clock .hour-wrapper .hour{
            width: 10px;
            height: 180px;
            margin: 0px auto;
            margin-top: 20px;
            background-color: rgb(197, 197, 197);
        }
        .clock .turn{
            width: 20px;
            height: 20px;
            margin-top: 338px;
            margin-left: 338px;
            background-color: black;
            border-radius: 50%;
            box-shadow: 0px 0px 10px rgba(255, 255, 255, 0.9);
        }

        @keyframes run{
            from{
                transform: rotateZ(0deg);
            }
            to{
                transform: rotateZ(360deg);
            }
        }
    </style>
</head>
<body>
    <div class="clock">
        <div class="hour-wrapper">
            <div class="hour"></div>
        </div>
        <div class="mine-wrapper">
            <div class="mine"></div>
        </div>
        <div class="sec-wrapper">
            <div class="sec"></div>
        </div>
        <div class="turn"></div>
    </div>
</body>
</html>

积跬步,至千里!加油,学习人!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值