美文网首页
css 实现多个小球绕轨道运动

css 实现多个小球绕轨道运动

作者: 八妹sss | 来源:发表于2021-02-26 15:13 被阅读0次

效果:

image.png

代码

<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <title>纯css3动画实现轨道旋转效果</title>
  <style>
    .outer-circle {
      display: inline-block;
      width:300px;
      height: 300px;
      margin: 50px auto;
      text-align: center;
      border-radius: 100%;
      background: palegoldenrod;
      position: relative;
    }
    .circle1 {
      width: 50px;
      height: 50px;
      line-height: 50px;
      background: cadetblue;
      border-radius: 100%;
      position: absolute;
      top:50%;
      left: 50%;
      margin-left: -25px;
      margin-top: -25px;
      animation: rotate1 5s infinite linear;
      /* transform: translate(0,-150px); */
    }
    .circle2 {
      width: 40px;
      height: 40px;
      line-height: 40px;
      background: yellowgreen;
      border-radius: 100%;
      position: absolute;
      top:50%;
      left: 50%;
      margin-left: -20px;
      margin-top: -20px;
      animation: rotate2 3s infinite linear;
      /* transform: translate(150px, 0); */
    }
    @keyframes rotate1 {
      from {
        transform: rotate(0turn) translate(0,-150px) rotate(1turn)
      }
      to {
        transform: rotate(1turn) translate(0,-150px) rotate(0turn)
      }
    }
    @keyframes rotate2 {
      from {
        transform: rotate(0turn) translate(150px, 0) rotate(1turn)
      }
      to {
        transform: rotate(1turn) translate(150px, 0) rotate(0turn)
      }
    }
  </style>
</head>

<body>
  <div class="outer-circle">
    <div class="circle1">Hello</div>
    <div class="circle2">Hello2</div>
  </div>
</body>
</html>

相关文章

网友评论

      本文标题:css 实现多个小球绕轨道运动

      本文链接:https://www.haomeiwen.com/subject/buimfltx.html