用CSS中的动画效果做一个转动的表

复制代码
<!DOCTYPE html>
<html lang="en">
     <head>
        <meta charset="utf-8">
        <title>
      
        </title>
        <style>
           *{
            margin:0;
            padding:0;
           } 
           /*制作表的样式*/
           .clock{
                width: 500px;
                height: 500px;
                margin:0 auto;
                margin-top:100px;
                border-radius: 50%;
                border:1px solid black;
                /*父绝子相*/
                position: relative;
                /*还可以设置表盘背景*/
               background-color: pink;
           }
           .clock>div{
                position:absolute;
                top:0;
                left:0;
                right:0;
                bottom:0;
                margin:auto;
           }
           /*设置时针*/
           .hour-wrapper{
                height: 70%;
                width: 70%;
                /*linear为匀速运动*/
                animation: run 7200s linear infinite;
           }
           .hour{
            height: 50%;
            width: 6px;
            background-color: #000;
            margin:0 auto;
           }
           /*设置分针*/
           .min-wrapper{
            height: 80%;
            width: 80%;
            animation: run 600s steps(60) infinite;  /*因为秒针设置为10s,所以分钟数为60*10s=600s*/
           }
           .min{
            height: 50%;
            width: 4px;
            background-color: #000;
            margin:0 auto;
           }
            /*设置秒针*/
            .sec-wrapper{
            height: 95%;
            width: 95%;
            animation: run 10s steps(60) infinite;
           }
           .sec{
            height: 50%;
            width: 2px;
            background-color: #f00;
            margin:0 auto;
           }
           
         /*设置动画*/
            @keyframes run {
                from{
                    transform:rotateZ(0);
                }
                to{
                    transform: rotateZ(360deg);
                }
            }

        </style>
     </head>
     <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>
         
     </body>
</html>
相关推荐
Yvonne爱编码6 分钟前
CSS- 4.3 绝对定位(position: absolute)&学校官网导航栏实例
前端·css·html·html5·hbuilder
繁依Fanyi1 小时前
ImgShrink:摄影暗房里的在线图片压缩工具开发记
开发语言·前端·codebuddy首席试玩官
卓律涤1 小时前
【找工作系列①】【大四毕业】【复习】巩固JavaScript,了解ES6。
开发语言·前端·javascript·笔记·程序人生·职场和发展·es6
Ten peaches2 小时前
Selenium-Java版(环境安装)
java·前端·selenium·自动化
心.c2 小时前
vue3大事件项目
前端·javascript·vue.js
姜 萌@cnblogs2 小时前
【实战】深入浅出 Rust 并发:RwLock 与 Mutex 在 Tauri 项目中的实践
前端·ai·rust·tauri
蓝天白云下遛狗2 小时前
google-Chrome常用插件
前端·chrome
多多*3 小时前
Spring之Bean的初始化 Bean的生命周期 全站式解析
java·开发语言·前端·数据库·后端·spring·servlet
linweidong3 小时前
在企业级应用中,你如何构建一个全面的前端测试策略,包括单元测试、集成测试、端到端测试
前端·selenium·单元测试·集成测试·前端面试·mocha·前端面经
满怀10153 小时前
【HTML 全栈进阶】从语义化到现代 Web 开发实战
前端·html