ram*_*ion 6 animation svg gradient
我想生成一个随时间变化的SVG梯度.
在这个示例代码中,我想生成一个椭圆,其渐变为红色,黄色条纹随着时间的推移从西向东传播(产生闪光效果):
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
<stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" >
<animate
attributeName="offset"
from="0%"
to="100%"
repeatCount="indefinite"/>
</stop>
<stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
</linearGradient>
</defs>
<ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad1)" />
</svg>
Run Code Online (Sandbox Code Playgroud)
这还不行,但我不确定是不是因为我做错了,或者这不是我用SVG渐变可以达到的效果.
你只需要动画的时间段.dur="5s"例如,添加为animate元素的属性.
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
<stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" >
<animate
attributeName="offset"
from="0%"
to="100%"
dur="5s"
repeatCount="indefinite"/>
</stop>
<stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
</linearGradient>
</defs>
<ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad1)" />
</svg>Run Code Online (Sandbox Code Playgroud)
这是一个适用于Firefox和Chrome 的示例:
此示例中使用此处规范中提供的values属性.
<linearGradient id="myG">
<stop offset="0" stop-color="#f15361">
</stop>
<stop offset=".25" stop-color="#fbaf4a">
<animate attributeName="offset" dur="5s" values="0;1;0"
repeatCount="indefinite" />
</stop>
<stop offset="1" stop-color="#f15361"/>
Run Code Online (Sandbox Code Playgroud)