Html+Css实现九大行星动画效果
时间: 2023-08-30 13:06:30 浏览: 161
好的,我可以为您提供一些基本的代码示例来实现九大行星动画效果。以下是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代码中的动画效果仅适用于最新版本的现代浏览器,而在旧版浏览器中可能会有兼容性问题。
阅读全文