CSS Animate SVG 笔画停在最后一帧

标签 css svg

CodePen

在上面的 codepen 中有一个 SVG,笔划动画显示在 View 中,但最后它就消失了。

有没有办法让它在加载后保持可见?

.path {
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  animation: dash 5s linear alternate;
}

@keyframes dash {
  from {
    stroke-dashoffset: 1000;
  }
  to {
    stroke-dashoffset: 0;
  }
}

最佳答案

将这两个属性添加到您的.path

  animation-fill-mode: forwards; // Stay on the last frame
    animation-iteration-count: 1;// Run only once 

CSS 将是:

.path {
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  animation: dash 5s linear alternate;
animation-fill-mode: forwards; // Stay on the last frame
    animation-iteration-count: 1;
}

Codepen 是 Here ,它工作正常。

关于CSS Animate SVG 笔画停在最后一帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30238333/

相关文章:

javascript - 当悬停快速发生时,动画未完成 SVG 悬停动画上的过渡

javascript - 我的内联 SVG 和嵌入式 SVG 存在问题

css - 使用 CSS 更改文本输入的值?

html - 默认设置内容为 'hidden'

html - 如何垂直对齐div中的元素?

javascript - 使用 jquery 操作::选择

css - 少操作

css - 动画 SVG 来回填充

javascript - 附加 svg 并拉伸(stretch)到父级

javascript - html2canvas 生成的图像未在图表中选择 svg