【问题标题】:pure CSS drawing circle animation纯CSS画圈动画
【发布时间】:2019-04-19 08:09:21
【问题描述】:

我写了一个纯css画圆动画,但是动画的时候两个半圆之间有一点空白。 (当动画结束时,他们就走了。)

谁能告诉我为什么会这样?

我的 HTML:

.circle__box {
  width: 200px;
  height: 200px;
  margin: 50px auto;
  position: relative;
}

.circle__wrapper {
  width: 100px;
  height: 200px;
  position: absolute;
  top: 0;
  overflow: hidden;
}

.circle__wrapper--right {
  right: 0;
}

.circle__wrapper--left {
  left: 0;
}

.circle__whole {
  width: 160px;
  height: 160px;
  border: 20px solid transparent;
  border-radius: 50%;
  position: absolute;
  top: 0;
  transform: rotate(-135deg);
}

.circle__right {
  border-top: 20px solid teal;
  border-right: 20px solid teal;
  right: 0;
  animation: circleRight 5s linear forwards;
}

.circle__left {
  border-bottom: 20px solid teal;
  border-left: 20px solid teal;
  left: 0;
  animation: circleLeft 5s linear forwards;
}

@keyframes circleRight {
  0% {
    transform: rotate(-135deg);
  }
  50%,
  100% {
    transform: rotate(45deg);
  }
}

@keyframes circleLeft {
  0%,
  50% {
    transform: rotate(-135deg);
  }
  100% {
    -webkit-transform: rotate(45deg);
  }
}
<div class="circle__box">
  <div class="circle__wrapper circle__wrapper--right">
    <div class="circle__whole circle__right"></div>
  </div>
  <div class="circle__wrapper circle__wrapper--left">
    <div class="circle__whole circle__left"></div>
  </div>
</div>

我的完整代码是here。谢谢。

【问题讨论】:

    标签: html css animation path geometry


    【解决方案1】:

    在这里,请检查。因为你分别给了.circle-left.circle-rightleft:0;right:0;,改成left:1px;right:1px;就完成了……

    .circle__box {
      width: 200px;
      height: 200px;
      margin: 50px auto;
      position: relative;
    }
    
    .circle__wrapper {
      width: 100px;
      height: 200px;
      position: absolute;
      top: 0;
      overflow: hidden;
    }
    
    .circle__wrapper--right {
      right: 0;
    }
    
    .circle__wrapper--left {
      left: 0;
    }
    
    .circle__whole {
      width: 160px;
      height: 160px;
      border: 20px solid transparent;
      border-radius: 50%;
      position: absolute;
      top: 0;
      transform: rotate(-135deg);
    }
    
    .circle__right {
      border-top: 20px solid teal;
      border-right: 20px solid teal;
      right: 1px;
      animation: circleRight 5s linear forwards;
    }
    
    .circle__left {
      border-bottom: 20px solid teal;
      border-left: 20px solid teal;
      left: 1px;
      animation: circleLeft 5s linear forwards;
    }
    
    @keyframes circleRight {
      0% {
        transform: rotate(-135deg);
      }
      50%,
      100% {
        transform: rotate(45deg);
      }
    }
    
    @keyframes circleLeft {
      0%,
      50% {
        transform: rotate(-135deg);
      }
      100% {
        -webkit-transform: rotate(45deg);
      }
    }
    <div class="circle__box">
      <div class="circle__wrapper circle__wrapper--right">
        <div class="circle__whole circle__right"></div>
      </div>
      <div class="circle__wrapper circle__wrapper--left">
        <div class="circle__whole circle__left"></div>
      </div>
    </div>

    【讨论】:

    • 好的,但是如果我没有设置left: 1pxright: 1px,为什么两个半圆不能合在一起呢?为什么它们不能装进包装纸里?当我注释掉动画时,在 0deg 和 180deg 上有一些东西。
    • 在我设置left: 1pxright: 1px 后,当我放大150% 或更大时,空白再次出现......
    • 为什么要放大?
    • 这是一个为客户设计的项目。他们也可能这样做。
    • 我认为没有人在放大时测试项目。这是一个愚蠢的方面。如我所见,放大 150% 后,我看不到任何像您看到的白线...
    【解决方案2】:

    这是我的解决方案:

    .circle__wrapper--right { right: 0; margin-right: 20px;}

    .circle__wrapper--left { left: 0; margin-left: 20px; }

    【讨论】:

      猜你喜欢
      • 2017-02-20
      • 2013-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多