地球环绕太阳CSS3动画

实现效果:

效果图

思路: 用border-radius实现圆形区域orbit,orbit进行rotate转动。

1.div布局

<div id="container">
		<div class="earth"></div>   <!--地球-->

		<div class="orbit" id="earth-orbit">   <!--轨道-->
			<img src="air.png" class="airplane"/>   <!--飞机不用转-->
		</div>
	</div>

2.css3样式

body{
  background-color: #20202c;
   height: 100vh;
}
#container{
  position: absolute;
  width: 400px;
  height:400px;
  left:calc(50% - 200px);
  top:calc(50% - 200px);
}
.earth{
  position: absolute;
  top: 150px;
  left: 150px;
  height: 100px;
  width: 100px;
  background-color: blue;
  border-radius: 50%;
  -webkit-box-shadow: 0 0 30px white;
          box-shadow: 0 0 30px white;
}
.orbit{
  border: solid;
  border-color: white transparent transparent transparent;
  border-radius: 50%;
  border-width: 1px 1px 0 0;
  -webkit-box-sizing: border-box;
          box-sizing: border-box;
  position: absolute;
   -webkit-transform: rotate(0deg);
          transform: rotate(0deg);
  -webkit-transform-origin: center;
          transform-origin: center; 
}
#earth-orbit{
  -webkit-animation: orbit 36.5s linear infinite;
  -o-animation: orbit 36.5s linear infinite;
  animation: orbit 36.5s linear infinite;
  height: 300px;
  left: 50px;
  top: 50px;
  width: 300px;
}
@-webkit-keyframes orbit{
  to {
    -webkit-transform: rotate(360deg);
            transform: rotate(360deg);
  }
}
@keyframes orbit{
  to {
    -webkit-transform: rotate(360deg);
            transform: rotate(360deg);
  }
}
.airplane{
  position: absolute;
  width:30px;
  height:30px;
  top:28px;
  left:28px;
  background-color: yellow;
  -webkit-transform:rotate(90deg);
  transfrom:rotate(90deg);
}
Table of Contents