CSS3地月星系旋轉效果

admin發表於2018-07-09

本章節分享一段程式碼例項,它實現了地月系旋轉效果。

月球圍繞地球旋轉,同時地球圍繞太陽旋轉。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
/*css reset */
body, ol, ul, li, dl, dt, dd, h1, h2, h3, h4, h5, h6, p, div {
  margin: 0;
  padding: 0;
}
body {
  background: #000;
}
.wrapper {
  width: 100%;
  margin: 0 auto;
}
.planet {
  width: 800px;
  height: 600px;
  margin: 100px auto;
  background-color: black;
  position: relative;
}
.planet div {
  position: absolute;
}
.sun {
  left: 350px;
  top: 250px;
  width: 100px;
  height: 100px;
  background: url(demo/CSS/img/ri.png) no-repeat;
}
.huan {
  width: 740px;
  height: 540px;
  left: 30px;
  top: 30px;
  border: 1px solid #222;
  border-radius: 55%;
}
.yzhou {
  animation: yzhou 20s ease-in-out infinite alternate;
}
.di {
  top: 0;
  left: 370px;
  width: 60px;
  height: 60px;
  transform-origin: 30px 400px;
  animation: yuan 40s linear infinite;
 }
.di2 {
  width: 60px;
  height: 60px;
  background: url(demo/CSS/img/di.png) no-repeat;
  position: relative;
  animation: zzhuan 5s linear infinite;
}
.yue {
  width: 23px;
  height: 23px;
  border-radius: 10px;
  background: url(demo/CSS/img/yue.png) center no-repeat;
  background-size: contain;
  position: absolute;
  top: 0;
  left: 75px;
  transform-origin: -46px 33px;
  animation: zzhuan 4s linear infinite;
}
@keyframes yzhou {
  100% {
    transform: translateY(-200px);
  }
}
@keyframes yuan {
  100% {
    transform: rotate(-360deg);
  }
}
@keyframes zzhuan {
  100% {
    transform: rotate(-360deg);
  }
}
</style>
</head>
<body>
  <div class="wrapper">
    <div class="planet">
      <div class="huan"></div>
      <div class="sun"></div>
      <div class="yzhou">
        <div class="di">
          <div class="di2">
            <div class="yue"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>
</html>

相關文章