gpt4 book ai didi

javascript - 像蜗牛一样在路径上进行 SVG 动画

转载 作者:行者123 更新时间:2023-11-28 05:22:18 27 4
gpt4 key购买 nike

我有以下 SVG,我想在移动后在路径上逐像素绘制圆圈。就像蜗牛离开时,他会在身后留下一道痕迹。所以我的问题是如何绘制浅红色圆圈? Snail effect

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" viewBox="0 0 1000 200" id="svgBox" style="background-color:#e4e4e4">
<path d="M3.858,58.607 c16.784-5.985,33.921-10.518,51.695-12.99c50.522-7.028,101.982,0.51,151.892,8.283c17.83,2.777,35.632,5.711,53.437,8.628 c51.69,8.469,103.241,11.438,155.3,3.794c53.714-7.887,106.383-20.968,159.374-32.228c11.166-2.373,27.644-7.155,39.231-4.449L10,10" stroke="grey" stroke-width="1" fill="none" id="animateMotion"/>
<circle cx="" cy="" r="5" fill="red">
<animateMotion dur="6s" repeatCount="0">
<mpath xlink:href="#animateMotion"/>
</animateMotion>
</circle>
</svg>

最佳答案

例如,您可以执行以下操作:

.path {
stroke-dasharray: 1230;
stroke-dashoffset: 1230;
animation: snail 6s linear forwards;
}

@keyframes snail {
to {
stroke-dashoffset: 0;
}
}
    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" viewBox="0 0 1000 200" id="svgBox" style="background-color:#e4e4e4">
<path class="path" d="M3.858,58.607 c16.784-5.985,33.921-10.518,51.695-12.99c50.522-7.028,101.982,0.51,151.892,8.283c17.83,2.777,35.632,5.711,53.437,8.628 c51.69,8.469,103.241,11.438,155.3,3.794c53.714-7.887,106.383-20.968,159.374-32.228c11.166-2.373,27.644-7.155,39.231-4.449L10,10" stroke="pink" stroke-width="12" fill="none" id="animateMotion"/>
<circle cx="" cy="" r="5" fill="red">
<animateMotion dur="6s" repeatCount="0">
<mpath xlink:href="#animateMotion"/>
</animateMotion>
</circle>
</svg>

关于javascript - 像蜗牛一样在路径上进行 SVG 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40440048/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com