我有一个动态SVG,在其中每个<path>
都在前一个<path>
之后开始。第一个<path>
是通过单击或0s开始的。
我有一个问题,如何在不使用JS(仅使用XML)的情况下停止动画。我点击以启动动画。在整个动画结束之前,我再次点击并触发了新的动画。然而,以前的动画继续运行,并且它混乱了所有从2开始的<path>
。
我已尝试了不同的选项(具有时间偏移的begin
;带有id.end
的begin
),但我还没有找到解决方案。也许比我更有经验的SVG专家可以帮助我?
Here is my SVG:
<svg xmlns="http://www.w3.org/2000/svg" width="109" height="109" viewBox="0 0 109 109" id="3005">
<g fill="none" stroke="#666" stroke-width="9" stroke-linecap="round" stroke-linejoin="round">
<g>
<path d="M50.75,19.5c0.1,1.3,0.37,3.74-0.19,5.21C43.57,43,32.73,60.29,14.5,75.04" />
<path d="M45,44.35c1.05,0,3.62,0.35,6.26,0.1c9.18-0.85,25.21-3.31,29.06-3.67c4.26-0.4,6.46,4.28,4.68,6.25C78.32,54.46,67.5,67,57.81,79.22" />
<path d="M42.52,68.33c10.16,5.01,26.25,20.59,28.79,28.38" />
</g>
</g>
<g fill="none" stroke="#000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round">
<g>
<path d="M50.75,19.5c0.1,1.3,0.37,3.74-0.19,5.21C43.57,43,32.73,60.29,14.5,75.04" stroke-dasharray="67.92" stroke-dashoffset="67.92">
<animate id="0" attributeName="stroke-dashoffset" values="67.92;0" dur="0.51s" fill="freeze" begin="0s;3005.click" />
</path>
<path d="M45,44.35c1.05,0,3.62,0.35,6.26,0.1c9.18-0.85,25.21-3.31,29.06-3.67c4.26-0.4,6.46,4.28,4.68,6.25C78.32,54.46,67.5,67,57.81,79.22" stroke-dasharray="87.4" stroke-dashoffset="87.4">
<animate attributeName="stroke-dashoffset" values="87.4" fill="freeze" begin="3005.click" />
<animate id="1" attributeName="stroke-dashoffset" values="87.4;0" dur="0.66s" fill="freeze" begin="0.end" />
</path>
<path d="M42.52,68.33c10.16,5.01,26.25,20.59,28.79,28.38" stroke-dasharray="41.01" stroke-dashoffset="41.01">
<animate attributeName="stroke-dashoffset" values="41.01" fill="freeze" begin="3005.click" />
<animate id="2" attributeName="stroke-dashoffset" values="41.01;0" dur="0.41s" fill="freeze" begin="1.end" />
</path>
</g>
</g>
</svg>
values
和keyTimes
的完美组合加上调整dur
正是我所需要的。你救了我的一天。只是想添加一个示例到你的建议中,这样以后更容易找到它。 - mihails.kuzmins