2017-07-28 103 views
0

我有以下SVG代码:SVG动画渐变色

<svg height="130" width="500"> 
 
    <defs> 
 
    <linearGradient id="logo-gradient" x1="0%" y1="0%" x2="100%" y2="100%"> 
 
     <stop offset="0%" stop-color="#054f16"> 
 
     <animate attributeName="stop-color" values="#054f16; #91bc9c" dur="4s" repeatCount="indefinite"></animate> 
 
     </stop> 
 
     <stop offset="100%" stop-color="#01FF89"> 
 
     <animate attributeName="stop-color" values="#91bc9c; #054f16" dur="4s" repeatCount="indefinite"></animate> 
 
     </stop> 
 
    </linearGradient> 
 
    </defs> 
 
    <ellipse cx="100" cy="70" rx="85" ry="55" fill="url(#logo-gradient)" /> 
 
    <text fill="#ffffff" font-size="45" font-family="Verdana" x="50" y="86">SVG</text> 
 
    Sorry, your browser does not support inline SVG. 
 
</svg>

我期待动画渐变中保持平稳的SVG容器流动,后面的文本。正如你可以从this fiddle看到的那样,它很跳跃。我该如何解决?谢谢!

回答

1

要让动画循环/返回起点,只需为每个values属性添加一个额外的值。该值应该是起始颜色。

<svg height="130" width="500"> 
 
    <defs> 
 
    <linearGradient id="logo-gradient" x1="0%" y1="0%" x2="100%" y2="100%"> 
 
     <stop offset="0%" stop-color="#054f16"> 
 
     <animate attributeName="stop-color" values="#054f16; #91bc9c; #054f16" dur="4s" repeatCount="indefinite"></animate> 
 
     </stop> 
 
     <stop offset="100%" stop-color="#01FF89"> 
 
     <animate attributeName="stop-color" values="#91bc9c; #054f16; #91bc9c" dur="4s" repeatCount="indefinite"></animate> 
 
     </stop> 
 
    </linearGradient> 
 
    </defs> 
 
    <ellipse cx="100" cy="70" rx="85" ry="55" fill="url(#logo-gradient)" /> 
 
    <text fill="#ffffff" font-size="45" font-family="Verdana" x="50" y="86">SVG</text> 
 
    Sorry, your browser does not support inline SVG. 
 
</svg>