css - 如何从左到右制作 svg svg 笔划线动画?

标签 css svg css-animations svg-animate

svg 笔画动画从右开始,但我想从左到右笔画动画形式。动画笔划后保持站立。可以在动画期间添加任何动画 css 类,如 fadeIn

.cls-1 {
  fill: none;
  stroke: #00a139;
  stroke-miterlimit: 10;
}

svg {
  width: 100%;
  height: 100vh;
  margin-left: auto;
  margin-right: auto;
  display: block;
  background: #1e1e1e;
}

#Path_70 {
  stroke-dasharray: 1800;
  stroke-dashoffset: 1800;
  animation: dash 5s linear forwards;
}

@keyframes dash {
  to {
    stroke-dashoffset: 0;
  }
}
<svg id="ex6" xmlns="http://www.w3.org/2000/svg" viewBox="2080.831 303.745 1673.195 406.547">
  <defs>
  </defs>
  <g id="Group_191" data-name="Group 191" transform="translate(2393 93)">
    <path id="Path_70" data-name="Path 70" class="cls-1" d="M1700.935,169.155s-227.809,11.434-421.654,140.759c-174.322,116.314-275.519,110.6-373.713,41.794C786.235,268.022,551.495-57.262,63.3,9.47" transform="translate(-361.422 210.687)"/>
  </g>
</svg>

最佳答案

您可以使 stroke-dashoffset 为负值:

.cls-1 {
  fill: none;
  stroke: #00a139;
  stroke-miterlimit: 10;
}

svg {
  width: 100%;
  height: 100vh;
  margin-left: auto;
  margin-right: auto;
  display: block;
  background: #1e1e1e;
}

#Path_70 {
  stroke-dasharray: 1800;
  stroke-dashoffset: -1800;
  animation: dash 5s linear forwards;
}

@keyframes dash {
  to {
    stroke-dashoffset: 0;
  }
}
<svg id="ex6" xmlns="http://www.w3.org/2000/svg" viewBox="2080.831 303.745 1673.195 406.547">
  <defs>
  </defs>
  <g id="Group_191" data-name="Group 191" transform="translate(2393 93)">
    <path id="Path_70" data-name="Path 70" class="cls-1" d="M1700.935,169.155s-227.809,11.434-421.654,140.759c-174.322,116.314-275.519,110.6-373.713,41.794C786.235,268.022,551.495-57.262,63.3,9.47" transform="translate(-361.422 210.687)"/>
  </g>
</svg>

关于css - 如何从左到右制作 svg svg 笔划线动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49913166/

相关文章:

javascript - 如何以编程方式在 CSS 动画中堆叠关键帧

css - 如何在这个纯 HTML/CSS 幻灯片中添加指向每个图像的链接?

具有两个步骤且没有过渡的CSS动画

javascript - CSS 和 jQuery : Element moving Element

css - 上标列表项

css - SVG 比例变换具有运动

html - CSS3 animation-delay 属性不工作

html - 如何为 SVG 中的路径元素着色?

html - 导航栏折叠不起作用

javascript - 使用 React-Toolbox 的按钮进行样式设置不起作用