html+div+动画效果,html+css3太阳系行星运转动画效果的实现代码

原标题:html+css3太阳系行星运转动画效果的实现代码

做一个太阳系八大行星的运转动画,不包括行星的卫星,所有行星围绕太阳公转,行星采用纯色,暂时没有自转。

效果静态图:

f195467eaf325aab0f75a16a622bbad1.png

动画中包括:太阳及各行星,运行轨道,行星公转动画。

先画好草图,设计好大小和位置,根据公转周期计算好动画执行的时间。

html的结构:

一个class为solarsys的div,作为太阳系容器元素,该div的position为relative。

行星轨道和行星都用div,position为absolute。

容器用relative和内部元素采用absolute的定位方式,比较简单的能实现效果,缺点就是大小是固定的。

XML/HTML Code复制内容到剪贴板

太阳系容器div的css:

定宽,定高,relative定位,页面内剧中对齐。

CSS Code复制内容到剪贴板

.solarsys{

width: 800px;

height: 800px;;

position: relative;

margin: 0 auto;

background-color: #000000;

padding: 0;

transform: scale(1);

}

太阳div的css:

按照设计的大小和位置,设定宽高,left,top。

设定颜色。

通过把boder-radius生成50%,把一个正方形变成圆形。

通过box-shadow的4层颜色设置实现太阳光晕。

CSS Code复制内容到剪贴板

.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;

}

行星轨道div的css:

假设是水星轨道。

按照设计的大小和位置,设定宽高,left,top。

背景色透明。

通过把boder-radius生成50%,把一个正方形变成圆形。

boder的类型设成虚线。

boder的颜色设成灰色。

宽度设1。

CSS Code复制内容到剪贴板

.mercuryOrbit {

left:342.5px;

top:342.5px;

height: 115px;

width: 115px;

background-color: transparent;

border-radius: 50%;

border-style: dashed;

border-color: gray;

p

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您提供一些基本的代码示例来实现九大行星动画效果。以下是HTML和CSS代码示例: HTML代码: ```html <div class="container"> <div class="sun"></div> <div class="mercury"></div> <div class="venus"></div> <div class="earth"></div> <div class="mars"></div> <div class="jupiter"></div> <div class="saturn"></div> <div class="uranus"></div> <div class="neptune"></div> </div> ``` CSS代码: ```css .container { position: relative; width: 600px; height: 600px; margin: 0 auto; } .sun { position: absolute; top: 50%; left: 50%; margin-top: -50px; margin-left: -50px; width: 100px; height: 100px; border-radius: 50%; background-color: #FFCE00; animation: spin 10s linear infinite; } @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } .mercury { position: absolute; top: 0; left: 50%; margin-left: -5px; width: 10px; height: 10px; border-radius: 50%; background-color: #C2B280; animation: orbit 2s linear infinite; } .venus { position: absolute; top: 0; left: 50%; margin-left: -15px; width: 30px; height: 30px; border-radius: 50%; background-color: #E6D6AD; animation: orbit 4s linear infinite; } .earth { position: absolute; top: 0; left: 50%; margin-left: -25px; width: 50px; height: 50px; border-radius: 50%; background-color: #3F4F5F; animation: orbit 6s linear infinite; } .mars { position: absolute; top: 0; left: 50%; margin-left: -35px; width: 70px; height: 70px; border-radius: 50%; background-color: #E45F56; animation: orbit 8s linear infinite; } .jupiter { position: absolute; top: 0; left: 50%; margin-left: -50px; width: 100px; height: 100px; border-radius: 50%; background-color: #E1B80D; animation: orbit 10s linear infinite; } .saturn { position: absolute; top: 0; left: 50%; margin-left: -65px; width: 130px; height: 130px; border-radius: 50%; background-color: #E1B80D; animation: orbit 12s linear infinite; } .uranus { position: absolute; top: 0; left: 50%; margin-left: -85px; width: 170px; height: 170px; border-radius: 50%; background-color: #9BC4E2; animation: orbit 14s linear infinite; } .neptune { position: absolute; top: 0; left: 50%; margin-left: -100px; width: 200px; height: 200px; border-radius: 50%; background-color: #6384B3; animation: orbit 16s linear infinite; } @keyframes orbit { from { transform: rotate(0deg) translate(150px) rotate(0deg); } to { transform: rotate(360deg) translate(150px) rotate(-360deg); } } ``` 以上代码将会在一个 600px x 600px 的容器内展示太阳系中的九大行星,每个行星都有自己的轨道和大小。太阳会以线性方式旋转,而行星则会沿着其轨道以相同的线性速度运动。请注意,上面的CSS代码中的动画效果仅适用于最新版本的现代浏览器,而在旧版浏览器中可能会有兼容性问题。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值