html - 我的 svg 在动画的某个时刻停止

标签 html css svg

我有一个 SVG 元素(见下文)动画但一段时间后它停止动画。我希望动画继续像这样 jsfiddle .

.path {
    stroke-dasharray: 20;
    animation: dash 10s linear;
}

@keyframes dash {
    to {
        stroke-dashoffset: 1000;
    }
}
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="340px"
     height="333px" viewBox="0 0 340 333" enable-background="new 0 0 340 333"
     xml:space="preserve">
    <path class="path" fill="#fff" stroke="#000" stroke-width="2"
          d="m121.3,34.6c-1.6-1.6-4.2-1.6-5.8,0l-51,51.1-51.1-51.1c-1.6-1.6-4.2-
             1.6-5.8,0-1.6,1.6-1.6,4.2 0,5.8l53.9,53.9c0.8,0.8 1.8,1.2 2.9,1.2
             1,0 2.1-0.4 2.9-1.2l53.9-53.9c1.7-1.6 1.7-4.2 0.1-5.8z"/>
</svg>

最佳答案

您只缺少 infinite 关键字。引用the docs了解更多。

.path {
    stroke-dasharray: 20;
    animation: dash 10s linear infinite;
}

@keyframes dash {
    to {
        stroke-dashoffset: 1000;
    }
}
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="340px"
     height="333px" viewBox="0 0 340 333" enable-background="new 0 0 340 333"
     xml:space="preserve">
    <path class="path" fill="#fff" stroke="#000" stroke-width="2"
          d="m121.3,34.6c-1.6-1.6-4.2-1.6-5.8,0l-51,51.1-51.1-51.1c-1.6-1.6-4.2-
             1.6-5.8,0-1.6,1.6-1.6,4.2 0,5.8l53.9,53.9c0.8,0.8 1.8,1.2 2.9,1.2
             1,0 2.1-0.4 2.9-1.2l53.9-53.9c1.7-1.6 1.7-4.2 0.1-5.8z"/>
    </svg>

关于html - 我的 svg 在动画的某个时刻停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47202086/

相关文章:

html - 在 IE EDGE 中,文本未在 flexbox 内换行

javascript - 按钮内的文本不像按钮的一部分?

html - 如何让我的 <p> 元素沿着 &lt;input&gt; 和 &lt;textarea&gt; 字段垂直居中?

html - 具有两列的嵌套 HTML 表格,td 未对齐

html - 只有一些 CSS 在移动设备上加载,在桌面上完美运行

javascript - 如何将 if 语句与 v-for 一起使用?

Javascript - 复制淡入淡出

css - 文本阴影和缩放

javascript - 追加时访问父数据

javascript - 加载 svg-pan-zoom.js 后居中 <g> 元素