1. 程式人生 > >css模擬太陽系旋轉效果

css模擬太陽系旋轉效果

程式設計師47行純css程式碼模擬太陽系旋轉效果

程式碼:

  <style>
body, html {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-color: #12162B;
}

.jawn {
  position: relative;
  background-color: #F8E71C;
  width: 10px;
  height: 10px;
  margin: 0 auto;
  border-radius: 50%;
}
.jawn:after, .jawn:before {
  content: "";
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
}
.jawn:after {
  left: -10px;
  top: -5px;
  background-color: #C7C2A6;
  transform-origin: 15px 10px;
  animation: axis 1s linear infinite;
}
.jawn:before {
  left: -25px;
  top: -15px;
  background-color: #009bff;
  transform-origin: 30px 20px;
  animation: axis 2s linear infinite;
}

@keyframes axis {
  0% {
    transform: rotateZ(0deg) translate3d(0, 0, 0);
  }
  100% {
    transform: rotateZ(360deg) translate3d(0, 0, 0);
  }
}

  </style>