请编写一个html实现太阳系运动效果
时间: 2023-04-08 09:03:31 浏览: 238
网页设计HTML+CSS太阳系动态网页
好的,我可以回答这个问题。以下是一个简单的HTML代码,可以实现太阳系的运动效果:
```
<!DOCTYPE html>
<html>
<head>
<title>太阳系运动效果</title>
<style>
body {
background-color: black;
}
.sun {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100px;
height: 100px;
border-radius: 50%;
background-color: yellow;
box-shadow: 0 0 50px 10px yellow;
}
.planet {
position: absolute;
top: 50%;
left: 50%;
transform-origin: top left;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: white;
box-shadow: 0 0 10px 5px white;
}
.mercury {
animation: mercury-orbit 4s linear infinite;
}
.venus {
animation: venus-orbit 8s linear infinite;
}
.earth {
animation: earth-orbit 12s linear infinite;
}
.mars {
animation: mars-orbit 16s linear infinite;
}
.jupiter {
animation: jupiter-orbit 20s linear infinite;
}
.saturn {
animation: saturn-orbit 24s linear infinite;
}
.uranus {
animation: uranus-orbit 28s linear infinite;
}
.neptune {
animation: neptune-orbit 32s linear infinite;
}
@keyframes mercury-orbit {
from {
transform: rotate(0deg) translateX(50px) rotate(0deg);
}
to {
transform: rotate(360deg) translateX(50px) rotate(-360deg);
}
}
@keyframes venus-orbit {
from {
transform: rotate(0deg) translateX(80px) rotate(0deg);
}
to {
transform: rotate(360deg) translateX(80px) rotate(-360deg);
}
}
@keyframes earth-orbit {
from {
transform: rotate(0deg) translateX(110px) rotate(0deg);
}
to {
transform: rotate(360deg) translateX(110px) rotate(-360deg);
}
}
@keyframes mars-orbit {
from {
transform: rotate(0deg) translateX(140px) rotate(0deg);
}
to {
transform: rotate(360deg) translateX(140px) rotate(-360deg);
}
}
@keyframes jupiter-orbit {
from {
transform: rotate(0deg) translateX(170px) rotate(0deg);
}
to {
transform: rotate(360deg) translateX(170px) rotate(-360deg);
}
}
@keyframes saturn-orbit {
from {
transform: rotate(0deg) translateX(200px) rotate(0deg);
}
to {
transform: rotate(360deg) translateX(200px) rotate(-360deg);
}
}
@keyframes uranus-orbit {
from {
transform: rotate(0deg) translateX(230px) rotate(0deg);
}
to {
transform: rotate(360deg) translateX(230px) rotate(-360deg);
}
}
@keyframes neptune-orbit {
from {
transform: rotate(0deg) translateX(260px) rotate(0deg);
}
to {
transform: rotate(360deg) translateX(260px) rotate(-360deg);
}
}
</style>
</head>
<body>
<div class="sun"></div>
<div class="planet mercury"></div>
<div class="planet venus"></div>
<div class="planet earth"></div>
<div class="planet mars"></div>
<div class="planet jupiter"></div>
<div class="planet saturn"></div>
<div class="planet uranus"></div>
<div class="planet neptune"></div>
</body>
</html>
```
这段代码使用了CSS的动画和变换功能,通过给每个行星添加不同的动画,实现了太阳系行星的运动效果。
阅读全文