用HTML,CSS,js写一个太阳系环绕3d动画
时间: 2023-03-01 14:40:53 浏览: 136
html+css3太阳系行星运转动画效果的实现代码
这是一份使用HTML, CSS 和 JavaScript 编写的太阳系环绕 3D 动画的代码。
HTML:
```
<!DOCTYPE html>
<html>
<head>
<style>
#universe {
width: 600px;
height: 600px;
perspective: 1000px;
margin: 0 auto;
}
.sphere {
position: absolute;
width: 100px;
height: 100px;
border-radius: 50%;
transform-style: preserve-3d;
}
.orbit {
position: absolute;
width: 600px;
height: 600px;
border-radius: 50%;
transform-style: preserve-3d;
animation: orbit 15s linear infinite;
}
@keyframes orbit {
from {
transform: rotateY(0deg);
}
to {
transform: rotateY(360deg);
}
}
</style>
</head>
<body>
<div id="universe">
<div class="orbit">
<div class="sphere sun"></div>
<div class="orbit earth">
<div class="sphere earth"></div>
<div class="orbit moon">
<div class="sphere moon"></div>
</div>
</div>
</div>
</div>
</body>
</html>
```
CSS:
```
#universe {
width: 600px;
height: 600px;
perspective: 1000px;
margin: 0 auto;
}
.sphere {
position: absolute;
width: 100px;
height: 100px;
border-radius: 50%;
transform-style: preserve-3d;
}
.orbit {
position: absolute;
width: 600px;
height: 600px;
border-radius: 50%;
transform-style: preserve-3d;
animation: orbit 15s linear infinite;
}
@keyframes orbit {
from {
transform: rotateY(0deg);
}
to {
transform: rotateY(360deg);
}
}
.sun {
background: radial-gradient(yellow, orange);
}
.earth {
background: blue;
transform: translateZ(200px) rotateY(60deg);
animation: earth-orbit 20s linear infinite;
}
@keyframes earth-orbit {
from {
transform: translateZ(200px) rotateY(0deg);
}
to {
transform: translateZ(200px) rotateY(360deg);
}
}
.moon {
background: gray;
transform: translateZ(50px) rotateY(30deg);
animation: moon-orbit 10s linear infinite;
}
@keyframes moon-orbit {
from {
transform: translateZ(50px) rotateY(0deg);
}
to {
transform: translateZ(50px) rotate
阅读全文