【发布时间】:2020-12-29 23:54:36
【问题描述】:
是否可以使用 css background 属性为 SVG 渐变集设置动画?
我尝试过使用 SVG animate 元素,这是一个示例:
<?xml version="1.0" encoding="utf-8"?>
<svg id="svg" version="1.1" style="display: block;" viewBox="0.148 0.121 399.909 187.745" xmlns="http://www.w3.org/2000/svg">
<defs>
<pattern id="pattern-0" x="0" y="0" width="25" height="25" patternUnits="userSpaceOnUse" viewBox="0 0 100 100">
<rect x="0" y="0" width="50" height="100" style="fill: black;"/>
</pattern>
<linearGradient id="gradient-3" gradientUnits="userSpaceOnUse" x1="221.781" y1="-17.569" x2="221.781" y2="162.313" gradientTransform="matrix(-0.999997, 0.002512, -0.002478, -0.986265, 326.399578, 161.652725)" spreadMethod="pad">
<stop offset="0" style="stop-color: #4a87db;"/>
<stop offset="1" style="stop-color: rgb(255, 255, 255);"/>
<animate attributeName="x1" dur="5000ms" repeatCount="indefinite"
from="0%" to="100%" />
</linearGradient>
</defs>
<g id="svgg">
<path id="path1" d="M 0.317 160.263 C 0.491 160.322 54.672 181.321 96.41 186.555 C 138.827 191.875 170.592 177.656 200.188 146.3 C 235.21 109.196 258.892 111.366 299.457 117.682 C 336.776 123.493 399.859 155.012 399.781 157.423 C 399.76 158.082 400 0 400 0 L 0 0" stroke="none" fill-rule="evenodd" style="fill: url(#gradient-3);"/>
</g>
</svg>
但动画并不流畅,我只想将蓝色从一个十六进制更改为另一个,而不是为 x1 属性设置动画。
【问题讨论】:
-
@RobertLongson 抱歉,我是 SVG 方面的菜鸟,将阅读如何做到这一点,谢谢
标签: html css svg svg-animate