六、动画 - 旋转的应用例子,时钟

news2024/10/7 6:58:21

目录:
1.前期准备知识
2.实操 - 做时钟
3.完整代码

一、前期准备知识

因为旋转都是默认元素中心来旋转,所以,我们可以通过父元素包裹子元素。

通过父元素旋转,然后父带动子元素,到时候可以通过影藏父元素的背景颜色,这样看起来就像子元素在旋转。

<style>

*{
  margin:0;
  padding:0;
}

.sec-wrapper{
  width: 300px;
  height: 300px;
  margin: 100px;
  /* 通过父类的方框来旋转,带动里面子类sec的旋转,就可以模拟时钟针的旋转 */
  animation:run 60s;
  background-color: silver;
}

.sec{
  width: 10px;
  height: 100px;
  background-color: red;
  margin: 0 auto;
}


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

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

<body>
  <div class="sec-wrapper">
    <div class="sec">
    </div>
  </div>
</body>

在这里插入图片描述

二、实操 - 做时钟

1.先做表盘,和对应的秒针

  <style>
/* 1.设置原型表盘 */
    .clock{
      width: 400px;
      height: 400px;
      background-color: silver;
      margin: 0 auto;
      margin-top: 100px;
      border-radius: 50%;

      position: relative;
    }

    /* 2.clock下面所有子元素div 都居中.
    通过子绝父相,让所有的子元素相对于父类进行居中
    */
    .clock > div{
      position:absolute;

      /* 居中 */
      left:0;
      right:0;
      top:0;
      bottom:0;
      margin: auto;
    
    }
  /*3.设置秒针 */
     .sec-wrapper{
      width: 90%;
      height: 90%;
      /* 流畅的转一圈 */
      /* animation:run 60s; */
      /* 如果想让他一步步,停顿走一格这种节奏用steps 
      
      测试的话:10s- 一圈 - 表示一分钟![请添加图片描述](https://img-blog.csdnimg.cn/019f80fd6ae546dfbc8dce37b82c285b.png)

      正常是60s 写
      */
 	/*5.使用动画 */
      animation:run 10s steps(60) infinite;
    }
    .sec{
      width: 2px;
      height: 50%;
      background-color: red;
      margin: 0 auto;
    }

  /* 4.设置旋转动画 */
    @keyframes run {
      from{
        transform:rotate(0)
      }
      to{
        transform: rotateZ(360deg);
      }
    }
  </style>

<body>
  <!-- 表盘 -->
  <div class="clock">
    <!-- 秒针-->
     <div class="sec-wrapper">
      <div class="sec"></div>
    </div>
  </div>
</body>

2.当秒针设置好后,时针和分钟就依次复制秒针的样式,然后做一些修改,他们代码如下:


/* 时钟 */
    .hour-wrapper{
      width: 70%;
      height: 70%;
      /* 10s * 60 * 12 
      时钟一直都在动,只不过很微小,所以不能用steps,而是用linear
      */
      animation:run 7200s linear infinite;
    }
    .hour{
      width: 6px;
      height: 50%;
      background-color: black;
      margin: 0 auto;
     
    }

    /* 分钟 */
    .min-wrapper{
      width: 80%;
      height: 80%;
      /* 60 * 10s */
      animation:run 600s steps(60) infinite;
    }
    .min{
      width: 4px;
      height: 50%;
      background-color: black;
      margin: 0 auto;
    }

  <!-- 时钟 -->
    <div class="hour-wrapper">
      <div class="hour"></div>
    </div>

     <!-- 分针-->
    <div class="min-wrapper">
      <div class="min"></div>
    </div>

3.如果此时我们想给表盘设置背景图片,直接给表盘元素设置background-image,但是很多时候给的图片可能过大,超过了我们的宽高,这时候可以用background-size: cover;来调整。

 /* 1.设置原型表盘 */
    .clock{
      width: 400px;
      height: 400px;
      background-color: silver;
      margin: 0 auto;
      margin-top: 100px;
      border-radius: 50%;
      position: relative;

      /* 背景图片太大,设置下bgsize:cover 铺满 */
      /* background-image: url(./11/bg.png); */
      background-image: url(./11/bg3.jpg);
      background-size: cover;
    }

三、完整代码

<style>
    .clock{
      width: 400px;
      height: 400px;
      margin: 0 auto;
      margin-top: 100px;
      border-radius: 50%;
      position:relative;
      /* 背景图片太大,设置下bgsize:cover 铺满 */
      /* background-image: url(./11/bg.png); */
      background-image: url(./11/bg3.jpg);
      background-size: cover;
    }
    /* clock下面所有子元素div 都居中 */
    .clock > div{
      position:absolute;
      left: 0;
      right: 0;
      bottom: 0;
      top: 0;
      margin:auto;
    }

    /* 时钟 */
    .hour-wrapper{
      width: 70%;
      height: 70%;
      /* 10s * 60 * 12 
      时钟一直都在动,只不过很微小,所以不能用steps,而是用linear
      */
      animation:run 7200s linear infinite;
    }
    .hour{
      width: 6px;
      height: 50%;
      background-color: black;
      margin: 0 auto;
     
    }

    /* 分钟 */
    .min-wrapper{
      width: 80%;
      height: 80%;
      /* 60 * 10s */
      animation:run 600s steps(60) infinite;
    }
    .min{
      width: 4px;
      height: 50%;
      background-color: black;
      margin: 0 auto;
    }

     /* 秒 */
     .sec-wrapper{
      width: 90%;
      height: 90%;
      /* 流畅的转一圈 */
      /* animation:run 60s; */
      /* 如果想让他一步步,停顿走一格这种节奏用steps 
      
      测试的话:10s- 一圈 - 表示一分钟
      正常是60s 写
      */
      animation:run 10s steps(60) infinite;
    }
    .sec{
      width: 2px;
      height: 50%;
      background-color: red;
      margin: 0 auto;
    }

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

  </style>
<body>
  <div class="clock">
    <!-- 时钟 -->
    <div class="hour-wrapper">
      <div class="hour"></div>
    </div>

     <!-- 分针-->
    <div class="min-wrapper">
      <div class="min"></div>
    </div>

     <!-- 秒针-->
     <div class="sec-wrapper">
      <div class="sec"></div>
    </div>


  </div>
  

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/694518.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

关于三元运算符强转的问题

1.int和char比较 public static void main(String[] args) {char x x;int i 10;char y 2;System.out.println(true? x: i);System.out.println(true? x: 1167);System.out.println(true?y:2);System.out.println((int)x);}JVM&#xff1a; public static void main(Stri…

CSS基础学习--23 CSS属性 选择器

一、定义 具有特定属性的HTML元素样式&#xff08;不仅仅是class和id&#xff09; 二、属性选择器 例子是把包含标题&#xff08;title&#xff09;的所有元素变为蓝色&#xff1a; <!DOCTYPE html> <html> <head> <style> [title] { color:blue; }…

Linux_CentOS_7.9修改更新默认时区

前言&#xff1a;近期一直在频繁部署虚拟机做系统测试发现Linux默认时区未做更改&#xff0c;这里做个记录留作参考。 查看服务器时区&#xff08;默认为纽约时间&#xff09; [rootorcl3 ~]# timedatectl 系统默认安装的所有时区&#xff0c;找到我们需要的时区 [rootor…

Proteus仿真之DAC(DAC0832)

1.数模/模数转换的目的&#xff1a;生活中常见的物理量如温度、流量、压力、位移、速度等都是一种模拟量。但是&#xff0c;计算机只能处理0、1的数字量&#xff0c;此时就需要将模拟量转为数字量。与此同时&#xff0c;MCU对模拟量设备进行控制时&#xff0c;如控制电动调节阀…

直播间自定义公屏视图的升级之路(View版)

目录 1.前言2.旧版设计的分析3.新版设计的分析4.代码实现&#xff08;View版本&#xff09;4.1.流式布局的实现4.1.1.测量4.1.2.布局 4.2针对需求优化流式布局4.2.1.测量4.2.2.布局 5.总结 1.前言 最近的版本呢&#xff0c;产品更新了一个直播间的需求&#xff0c;原本直播间的…

蓝库云|企业如何建立自己的供应商管理系统?零代码工具带来惊喜

在面对采购的物品和服务比较复杂多样的企业&#xff0c;都需要管理大量的供应商&#xff0c;因此需要更加有效和专业的供应商管理系统。随着数字化转型的意识不断增强&#xff0c;中小型企业也越来越意识到采用供应商系统的必要性&#xff0c;以提高采购效率和质量&#xff0c;…

LangChain 使用文本描述的方式操作MySQL中的数据

一、LangChain 使用文本描述的方式操作MySQL中的数据 在 LangChain 中提供了 SQLDatabaseChain &#xff0c;可以通过语义文本去操作 MySQL中的数据&#xff0c;例如在 MySQL 中有如下表数据&#xff1a; 用户表 CREATE TABLE user (id int NOT NULL AUTO_INCREMENT COMMENT…

HTML5 Canvas动画实例

在开发在线游戏时&#xff0c;绘制动画是非常重要的。本文介绍一个使用Canvas API实现的动画实例——游戏人物的跑步动画。 01、动画的概念及原理 1、动画 动画是通过一幅幅静止的、内容不同的画面(即帧)快速播放来呈现的&#xff0c;使人们在视觉上产生动的感觉。这是利用了…

如何让VSCode不生成 tempcoderunnerfile.py

原因 runcode插件默认包含执行选中文本功能&#xff0c;当运行程序时会优先执行光标选中的代码并生成temp文件 解决方法 方法一&#xff1a;删除生成文件 在setting.json中添加 "code-runner.executorMap": {"php": "php $fullFileName &&am…

【Linux】Ubuntu20.04使用xrdp远程桌面时,gnome桌面环境没有最小化、任务栏等问题

一、问题背景 如下图所示&#xff0c;终端窗口没有最小化&#xff0c;因此只能关闭或移到一边去。 二、解决办法 在安装任何扩展前&#xff0c;需要将xrdp的桌面尽量向原生桌面靠拢。 在~/.xsessionrc配置文件中添加下面三行。 export GNOME_SHELL_SESSION_MODEubuntu ex…

Mediapipe 人像分割;实时更换背景;人脸添加特效

参考&#xff1a; https://zhuanlan.zhihu.com/p/476351994 1、Mediapipe 人像分割 import cv2 import mediapipe as mp import numpy as np mp_drawing mp.solutions.drawing_utils mp_selfie_segmentation mp.solutions.selfie_segmentation # 图片人物抠图: IMAGE_FILES…

idea生成serialVersionUID序列号

设置idea file->settings,搜索serialVersionUID&#xff0c;勾选框起来的两项 实体类实现Serializable接口 Data public class User implements Serializable { }鼠标放到类名上 点击提示的uid 生成的uid 结束&#xff01; hy:17 生活是一面镜子&#xff0c;给予我们…

springboot 停车场管理系统-计算机毕设 附源码82061

springboot 停车场管理系统 2023年5月 摘要 由于数据库和数据仓库技术的快速发展&#xff0c;停车场管理系统建设越来越向模块化、智能化、自我服务和管理科学化的方向发展。停车场管理系统对处理对象和服务对象&#xff0c;自身的系统结构&#xff0c;处理能力&#xff0c;都…

GO 基本配置

其他 IDEA 配置go语言环境 https://blog.csdn.net/weixin_45719444/article/details/121726325 关于IDEA的 plugins下找不到GO插件 点击安装 安装插件 Go 安装插件 Generate struct tags for golang

Flink CDC 2.4 正式发布,新增 Vitess 数据源,更多连接器支持增量快照,升级 Debezium 版本...

01 Flink CDC 简介 Flink CDC [1] 是基于数据库的日志 CDC 技术&#xff0c;实现了全增量一体化读取的数据集成框架。配合 Flink 优秀的管道能力和丰富的上下游生态&#xff0c;Flink CDC 可以高效实现海量数据的实时集成。 作为新一代的实时数据集成框架&#xff0c;Flink CDC…

二进制搭建Kubernetes集群(三)——部署多master

本文将完成多master集群的部署&#xff0c;即部署master02&#xff0c;以及nginx负载均衡、keepalived高可用 多master集群架构图&#xff1a; 架构说明&#xff1a; node节点的kubelet只能对接一个master节点的apiserver&#xff0c;不可能同时对接多个master节点的apiserver…

【Solr】中文分词配置

提示&#xff1a;在设置中文分词前需确保已经生成过core&#xff0c;未生成core的可以使用&#xff1a;solr create -c "自定义名称"进行定义。 未分词前的效果预览&#xff1a; 下载分词器&#xff1a; 下载地址: https://mvnrepository.com/artifact/com.github.m…

山西电力市场日前价格预测【2023-06-29】

日前价格预测 预测明日&#xff08;2023-06-29&#xff09;山西电力市场全天平均日前电价为407.26元/MWh。其中&#xff0c;最高日前价格为539.37元/MWh&#xff0c;预计出现在21: 15。最低日前电价为312.43元/MWh&#xff0c;预计出现在13: 00。以上预测仅供学习参考&#xff…

Java调用ssl异常,javax.net.ssl.SSLHandshakeException: No appropriate protocol

现象&#xff1a;sqlserver 2017 安装在docker里&#xff0c;系统是mac 13&#xff0c;java 1.8.371运行java程序提示上面ssl错误&#xff0c;根据百度提供的方法&#xff0c;修改文件&#xff0c;重启程序搞定。 解决办法&#xff1a;java.security 找到这个文件修改保存 发…

RPC(Remote Procedure Call)学习

目录 一、概念 二、RPC 调用基本流程 一、概念 RPC 全称是 Remote Procedure Call &#xff08;远程过程调用&#xff09;&#xff0c;它是一种通过网络从远程计算机程序上请求服务&#xff0c;可以提供终结点映射程序以及RPC服务&#xff0c;而不需要了解底层网络技术的协议…