【问题标题】:Is there a way to get smooth css keyframes animation?有没有办法获得平滑的 css 关键帧动画?
【发布时间】:2019-09-21 00:54:40
【问题描述】:

我正在尝试制作一个加载图标,其中一条线在 z 轴上连续来回移动。线条在移动,但我没有得到平滑的过渡。

    .loading{
      width: 50%;
      border: 1px solid black;
      height: 300px;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .line{
      border: 1px solid red;
      width: 20px;
      height: 140px;
      animation: round 2s infinite;
    }
    @keyframes round{
      25%{
        margin-right: -300px;
        height: 75px;
      }
      50%{
        height: 50px;
        width: 7px;
      }
      75%{
        margin-right: 300px;
        height: 75px;
      }
      100%{
        height: 140px;
      }
    }
  <div class="container">
    <div class="loading">
      <div class="line"></div>
    </div>
  </div>

当线条到达主要位置时它会停止然后开始移动,如何获得线性动画。

【问题讨论】:

  • google 用于线性简化 css。在无限之后添加线性

标签: html css css-animations


【解决方案1】:

对于linear 缓动动画,请点赞

infinite linear;

为了性能,不要使用边距或位置属性。请改用transform: translate(x, y)

PS:Z轴通常表示深度...

【讨论】:

  • 这一点怎么强调都不过分。实际上,很少有属性可以利用硬件加速来始终如一地产生超级流畅的动画。这篇文章很好地分解了它,并提供了可以清楚地看到卡顿以及如何修复它的示例:smashingmagazine.com/2016/12/gpu-animation-doing-it-right
猜你喜欢
  • 2015-01-05
  • 2015-06-22
  • 2019-03-11
  • 1970-01-01
  • 2014-09-10
  • 1970-01-01
  • 2020-09-09
  • 1970-01-01
  • 2020-01-07
相关资源
最近更新 更多