在SVG中,为<animateMotion>
元素添加缓出效果,可以通过使用<animate>
元素结合ease-out
缓动函数实现
<svg width="500" height="500" xmlns="http://www.w3.org/2000/svg">
<path id="motionPath" d="M10,80 Q100,10 200,80 T400,160" fill="none" stroke="black" />
<circle cx="0" cy="0" r="5" fill="red">
<animateMotion dur="5s" repeatCount="indefinite">
<mpath href="#motionPath" />
</animateMotion>
<animate attributeName="cx" dur="5s" values="0;400" repeatCount="indefinite" calcMode="spline" keySplines="0.42 0 0.58 1" />
<animate attributeName="cy" dur="5s" values="0;160" repeatCount="indefinite" calcMode="spline" keySplines="0.42 0 0.58 1" />
</circle>
</svg>
上面的代码创建了一个SVG动画,一个小圆沿着<path>
元素定义的路径移动。通过<animate>
元素,我们设置了cx
和cy
属性的动画在5秒内从初始值过渡到结束值,并使用spline
计算模式和keySplines
属性定义缓出效果。ease-out
缓动函数对应的keySplines
值为"0.42 0 0.58 1"
。
这样,您就可以为SVG <animateMotion>
元素添加缓出效果了。
领取专属 10元无门槛券
手把手带您无忧上云