css动画反转

标签 css svg css-animations stroke-dasharray

我做了一个 css 动画,但我没有反向动画。我尝试了动画的变体版本,但我没有。它有一些错误。

.animation {
  stroke-dasharray: 296 0;
  stroke-dashoffset: 296;
  animation: geri-sayim 5s linear forwards;
}

.animation-reverse{
  stroke-dasharray: 296 296;
  stroke-dashoffset: 0;
  animation: doldur 2s linear forwards;
}

@keyframes geri-sayim {
  100% { stroke-dasharray: 296; }
}

@keyframes doldur {
  100% { stroke-dasharray: 0; }
}

.geri-sayim-sayaci{
  width:100px;
}
<div class="geri-sayim-sayaci">
  <svg class="viewbox" viewBox="-5 -5 110 110">
    <circle id="progress" class="animation-reverse" cx="50" cy="50" r="47"
            transform="rotate(-90 50 50)" pointer-events="all"
            stroke="#1e8bff" stroke-width="8" fill="none"/>
  </svg>
</div>

最佳答案

这是一种逻辑行为,因为您正在为 stroke-dasharray 指定一个值(尝试手动将此值更改为 0,您会看到)。我想你想要这样的东西,你需要用一个 0 指定两个值:

.animation {
  stroke-dasharray: 296 0;
  stroke-dashoffset: 296;
  animation: geri-sayim 2s linear forwards;
}

.animation-reverse{
  stroke-dasharray: 296 296;
  stroke-dashoffset: 0;
  animation: doldur 2s linear forwards;
}

@keyframes geri-sayim {
  100% { stroke-dasharray: 296 296; }
}

@keyframes doldur {
  100% { stroke-dasharray: 0 296; }
}

.geri-sayim-sayaci{
  width:100px;
}
<div class="geri-sayim-sayaci">
  <svg class="viewbox" viewBox="-5 -5 110 110">
    <circle id="progress" class="animation-reverse" cx="50" cy="50" r="47"
            transform="rotate(-90 50 50)" pointer-events="all"
            stroke="#1e8bff" stroke-width="8" fill="none"/>
  </svg>
</div>
<div class="geri-sayim-sayaci">
  <svg class="viewbox" viewBox="-5 -5 110 110">
    <circle id="progress" class="animation" cx="50" cy="50" r="47"
            transform="rotate(-90 50 50)" pointer-events="all"
            stroke="#1e8bff" stroke-width="8" fill="none"/>
  </svg>
</div>

或者您可以考虑在只需要一个值的地方设置 stroke-dashoffset 动画:

.animation {
  stroke-dasharray: 296;
  stroke-dashoffset: 296;
  animation: geri-sayim 2s linear forwards;
}

.animation-reverse{
  stroke-dasharray: 296;
  stroke-dashoffset: 0;
  animation: doldur 2s linear forwards;
}

@keyframes geri-sayim {
  100% { stroke-dashoffset: 0; }
}

@keyframes doldur {
  100% { stroke-dashoffset: 296; }
}

.geri-sayim-sayaci{
  width:100px;
}
<div class="geri-sayim-sayaci">
  <svg class="viewbox" viewBox="-5 -5 110 110">
    <circle id="progress" class="animation-reverse" cx="50" cy="50" r="47"
            transform="rotate(-90 50 50)" pointer-events="all"
            stroke="#1e8bff" stroke-width="8" fill="none"/>
  </svg>
</div>
<div class="geri-sayim-sayaci">
  <svg class="viewbox" viewBox="-5 -5 110 110">
    <circle id="progress" class="animation" cx="50" cy="50" r="47"
            transform="rotate(-90 50 50)" pointer-events="all"
            stroke="#1e8bff" stroke-width="8" fill="none"/>
  </svg>
</div>

关于css动画反转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48965970/

相关文章:

javascript - autoprefixer watch 任务配置

javascript - 将标题悬停在 SVG 圆上

javascript - 这个 CSS 动画链应该无限运行,但它没有

html - CSS 文本幻灯片

css - 在两个不同的时间排队相同的动画,而不复制代码和提供新名称?

php - 菜单和 PHP GET CSS 选择器中包含的 CSS 文件

html - 如何使此文本与我的图像一致?布局问题

html - CSS: Lining::before content to middle of element

editor - 有什么好的小型或基础SVG编辑器?

javascript - 为什么 getComputedTextLength() 在 Chrome 和 Firefox 中给出不同的结果?