<svg viewBox="0 0 520 520" width="500" style='border: 1px solid black'>
<defs>
<linearGradient id="MyGradient">
<stop offset="0" style="stop-color:red;"/>
<stop offset="100%" style="stop-color:blue;">
<animate attributeName="offset"
from="0%" to="100%" dur="5s"
repeatCount="indefinite"/>
</stop>
</linearGradient>
</defs>
<circle cx="75" cy="75" r="70" fill="url(#MyGradient)"/>
</svg>
速写:
为了使颜色替换动画起作用,您需要在代码中将其替换
from="0%" to="100%"为from="0" to="1"要发生完整的颜色变化,您需要为两种颜色的偏移设置动画
点击后动画会开始
其他悬停动画选项
在动画的开始和结束状态,渐变从两种颜色变为另外两种颜色。
文本的渐变动画