Java基础、中级、高级、架构面试资料

使用HTML5+CSS3实现太阳系9大行星的运转动画

HTML5 herman 9263浏览 0评论
公告:“业余草”微信公众号提供免费CSDN下载服务(只下Java资源),关注业余草微信公众号,添加作者微信:xttblog2,发送下载链接帮助你免费下载!
本博客日IP超过2000,PV 3000 左右,急需赞助商。
极客时间所有课程通过我的二维码购买后返现24元微信红包,请加博主新的微信号:xttblog2,之前的微信号好友位已满,备注:返现
受密码保护的文章请关注“业余草”公众号,回复关键字“0”获得密码
所有面试题(java、前端、数据库、springboot等)一网打尽,请关注文末小程序
视频教程免费领
腾讯云】1核2G5M轻量应用服务器50元首年,高性价比,助您轻松上云

CSS3是最新的CSS标准,CSS3中的有很多新特性。在这篇文章中我们主要使用到的CSS3知识点如下:
1.boder-radius圆角边框属性
2.transform属性(rotate关键帧动画)
3.animation动画与div元素绑定
4.transform-origin设置旋转元素的基点位置属性

我们先看下最终的运行效果图:
太阳系运转动画
全部代码如下:

<!DOCTYPE html>
<html>
<head>
    <style>
        .solarsys{
            width: 800px;
            height: 800px;;
            position: relative;
            margin: 0 auto;
            background-color: #000000;
            padding: 0;
            transform: scale(1);
        }
        /*太阳 www.xttblog.com*/
        .sun {
            left:357px;
            top:357px;
            height: 90px;
            width: 90px;
            background-color: rgb(248,107,35);
            border-radius: 50%;
            box-shadow: 5px 5px 10px rgb(248,107,35), 
				-5px -5px 10px rgb(248,107,35), 
				5px -5px 10px rgb(248,107,35), 
				-5px 5px 10px rgb(248,107,35);
            position: absolute;
            margin: 0;
        }
        /*水星 www.xttblog.com*/
        .mercury {
            left:337.5px;
            top:395px;
            height: 10px;
            width: 10px;
            background-color: rgb(166,138,56);
            border-radius: 50%;
            position: absolute;
            transform-origin: 62.5px 5px;
            animation: rotate 1.5s infinite linear;
        }
        /*水星轨道 www.xttblog.com*/
        .mercuryOrbit {
            left:342.5px;
            top:342.5px;
            height: 115px;
            width: 115px;
            background-color: transparent;
            border-radius: 50%;
            border-style: dashed;
            border-color: gray;
            position: absolute;
            border-width: 1px;
            margin: 0px;
            padding: 0px;
        }
        /*金星 www.xttblog.com*/
        .venus {
            left:309px;
            top:389px;
            height: 22px;
            width: 22px;
            background-color: rgb(246,157,97);
            border-radius: 50%;
            position: absolute;
            transform-origin: 91px 11px;
            animation: rotate 3.84s infinite linear;
        }
        /*金星轨道 www.xttblog.com*/
        .venusOrbit {
            left:320px;
            top:320px;
            height: 160px;
            width: 160px;
            background-color: transparent;
            border-radius: 50%;
            border-style: dashed;
            border-color: gray;
            position: absolute;
            border-width: 1px;
            margin: 0px;
            padding: 0px;
        }
        /*地球 www.xttblog.com*/
        .earth {
            left:266.5px;
            top:391px;
            height: 18px;
            width: 18px;
            background-color: rgb(115,114,174);
            border-radius: 50%;
            position: absolute;
            transform-origin: 134px 9px;
            animation: rotate 6.25s infinite linear;
        }
        /*地球轨道 www.xttblog.com*/
        .earthOrbit {
            left:275px;
            top:275px;
            height: 250px;
            width: 250px;
            background-color: transparent;
            border-radius: 50%;
            border-style: dashed;
            border-color: gray;
            position: absolute;
            border-width: 1px;
            margin: 0px;
            padding: 0px;
        }
        /*火星 www.xttblog.com*/
        .mars {
            left:222.5px;
            top:392.5px;
            height: 15px;
            width: 15px;
            background-color: rgb(140,119,63);
            border-radius: 50%;
            position: absolute;
            transform-origin: 177.5px 7.5px;
            animation: rotate 11.75s infinite linear;
        }
         /*火星轨道 www.xttblog.com*/
        .marsOrbit {
            left:230px;
            top:230px;
            height: 340px;
            width: 340px;
            background-color: transparent;
            border-radius: 50%;
            border-style: dashed;
            border-color: gray;
            position: absolute;
            border-width: 1px;
            margin: 0px;
            padding: 0px;
        }
        /*木星 www.xttblog.com*/
        .jupiter {
            left:134px;
            top:379px;
            height: 42px;
            width: 42px;
            background-color: rgb(156,164,143);
            border-radius: 50%;
            position: absolute;
            transform-origin: 266px 21px;
            animation: rotate 74.04s infinite linear;
        }
        /*木星轨道 www.xttblog.com*/
        .jupiterOrbit {
            left:155px;
            top:155px;
            height: 490px;
            width: 490px;
            background-color: transparent;
            border-radius: 50%;
            border-style: dashed;
            border-color: gray;
            position: absolute;
            border-width: 1px;
            margin: 0px;
            padding: 0px;
        }
        /*土星 www.xttblog.com*/
        .saturn {
            left:92px;
            top:387px;
            height: 26px;
            width: 26px;
            background-color: rgb(215,171,68);
            border-radius: 50%;
            position: absolute;
            transform-origin: 308px 13px;
            animation: rotate 183.92s infinite linear;
        }
        /*土星轨道 www.xttblog.com*/
        .saturnOrbit {
            left:105px;
            top:105px;
            height: 590px;
            width: 590px;
            background-color: transparent;
            border-radius: 50%;
            border-style: dashed;
            border-color: gray;
            position: absolute;
            border-width: 1px;
            margin: 0px;
            padding: 0px;
        }
        /*天王星 www.xttblog.com*/
        .uranus {
            left:41.5px;
            top:386.5px;
            height: 27px;
            width: 27px;
            background-color: rgb(164,192,206);
            border-radius: 50%;
            position: absolute;
            transform-origin: 358.5px 13.5px;
            animation: rotate 524.46s infinite linear;
        }
        /*天王星轨道 www.xttblog.com*/
        .uranusOrbit {
            left:55px;
            top:55px;
            height: 690px;
            width: 690px;
            background-color: transparent;
            border-radius: 50%;
            border-style: dashed;
            border-color: gray;
            position: absolute;
            border-width: 1px;
            margin: 0px;
            padding: 0px;
        }
        /*海王星 www.xttblog.com*/
        .neptune {
            left:10px;
            top:390px;
            height: 20px;
            width: 20px;
            background-color: rgb(133,136,180);
            border-radius: 50%;
            position: absolute;
            transform-origin: 390px 10px;
            animation: rotate 1028.76s infinite linear;
        }
        /*海王星轨道 www.xttblog.com*/
        .neptuneOrbit {
            left:20px;
            top:20px;
            height: 760px;
            width: 760px;
            background-color: transparent;
            border-radius: 50%;
            border-style: dashed;
            border-color: gray;
            position: absolute;
            border-width: 1px;
            margin: 0px;
            padding: 0px;
        }
        @keyframes rotate {
            100% {
                transform: rotate(-360deg);
            }
        }
    </style>
</head>
<body>
    <div class="solarsys">
        <!--太阳-->
        <div class='sun'></div>
        <!--水星轨道-->
        <div class='mercuryOrbit'></div>
        <!--水星-->
        <div class='mercury'></div>
        <!--金星轨道-->
        <div class='venusOrbit'></div>
        <!--金星-->
        <div class='venus'></div>
        <!--地球轨道-->
        <div class='earthOrbit'></div>
        <!--地球-->
        <div class='earth'></div>
        <!--火星轨道-->
        <div class='marsOrbit'></div>
        <!--火星-->
        <div class='mars'></div>
        <!--木星轨道-->
        <div class='jupiterOrbit'></div>
        <!--木星-->
        <div class='jupiter'></div>
        <!--土星轨道-->
        <div class='saturnOrbit'></div>
        <!--土星-->
        <div class='saturn'></div>
        <!--天王星轨道-->
        <div class='uranusOrbit'></div>
        <!--天王星-->
        <div class='uranus'></div>
        <!--海王星轨道-->
        <div class='neptuneOrbit'></div>
        <!--海王星-->
        <div class='neptune'></div>
    </div>
</body>
</html>

点此查看运行效果
版权声明:本文为博主原创文章,未经博主允许不得转载。

业余草公众号

最后,欢迎关注我的个人微信公众号:业余草(yyucao)!可加作者微信号:xttblog2。备注:“1”,添加博主微信拉你进微信群。备注错误不会同意好友申请。再次感谢您的关注!后续有精彩内容会第一时间发给您!原创文章投稿请发送至532009913@qq.com邮箱。商务合作也可添加作者微信进行联系!

本文原文出处:业余草: » 使用HTML5+CSS3实现太阳系9大行星的运转动画