CSS3地月星系旋转效果

2018-7-9 11:30| 作者: admin| 查看: 374| 评论: 0|来自: 蚂蚁部落

本章节分享一段代码实例,它实现了地月系旋转效果。

月球围绕地球旋转,同时地球围绕太阳旋转。

代码实例如下:

[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>

鲜花

握手

雷人

路过

鸡蛋

最新评论

返回顶部