css制作自动旋转的钟表

1、钟表制作过程
  1. 制作最外层圆环
    在这里插入图片描述
  2. 绘制时间刻度(定位+transform)
    在这里插入图片描述
  3. 绘制内表盘(作用:放置钟表最中间,遮挡住时间刻度,只留下部分-达到时间刻度的效果)
    在这里插入图片描述
  4. 绘制表针(时、分、秒)
    在这里插入图片描述
  5. 绘制最内层圆环(表针遮挡层)
    在这里插入图片描述
  6. 分别给时针、分针、秒针添加动画
2、具体代码

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

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .box {
      width: 240px;
      height: 240px;
      margin: 100px auto;
      border: 5px solid #ccc;
      border-radius: 50%;
      position: relative;
    }

    .time {
      width: 4px;
      height: 100%;
      background-color: #ccc;
      position: absolute;
      top: 0;
      left: 118px;
    }

    .two {
      transform: rotate(30deg);
    }

    .three {
      transform: rotate(60deg);
    }

    .four {
      transform: rotate(90deg);
    }

    .five {
      transform: rotate(120deg);
    }

    .six {
      transform: rotate(150deg);
    }

    .mask1 {
      width: 220px;
      height: 220px;
      border-radius: 50%;
      background-color: #fff;
      position: absolute;
      left: 10px;
      top: 10px;
    }

    .hour,
    .min,
    .sec {
      height: 2px;
      position: absolute;
      left: 120px;
      top: 119px;
      transform-origin: 0px 1px;
    }

    .hour {
      width: 60px;
      background-color: green;
      transform: rotate(-90deg);
      animation: hourMove 86400s linear infinite;
    }

    @keyframes hourMove {
      0% {
        transform: rotate(-90deg);
      }

      100% {
        transform: rotate(270deg);
      }
    }

    .min {
      width: 80px;
      background-color: blue;
      transform: rotate(-30deg);
      animation: minMove 3600s linear infinite;
    }

    @keyframes minMove {
      0% {
        transform: rotate(-30deg);
      }

      100% {
        transform: rotate(330deg);
      }
    }

    .sec {
      width: 100px;
      background-color: red;
      animation: secMove 60s linear infinite;
    }

    @keyframes secMove {
      0% {
        transform: rotate(0deg);
      }

      100% {
        transform: rotate(360deg);
      }
    }

    .mask2 {
      width: 20px;
      height: 20px;
      border-radius: 50%;
      background-color: #ccc;
      position: absolute;
      top: 110px;
      left: 110px;
    }
  </style>
</head>

<body>
  <div class="box">
    <!-- 刻度值 -->
    <div class="time one"></div>
    <div class="time two"></div>
    <div class="time three"></div>
    <div class="time four"></div>
    <div class="time five"></div>
    <div class="time six"></div>
    <!-- 内表盘遮挡层 -->
    <div class="mask1"></div>
    <!-- 时针、分针、秒针 -->
    <div class="hour"></div>
    <div class="min"></div>
    <div class="sec"></div>
    <!-- 最内层圆环(表针遮挡层) -->
    <div class="mask2"></div>
  </div>
</body>

</html>

前端进阶精选:点此去

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值