【发布时间】:2015-12-09 23:32:51
【问题描述】:
我希望一个 svg 对象从颜色“A”渐变为颜色“B”,然后无限期地变回颜色“A”。
到目前为止,我使用的成功有限
<animate attributeName="fill" from="colorA" to="colorB" dur="10s" repeatCount="indefinite" />
但这不允许我淡出颜色“A”。
任何帮助将不胜感激。
【问题讨论】:
我希望一个 svg 对象从颜色“A”渐变为颜色“B”,然后无限期地变回颜色“A”。
到目前为止,我使用的成功有限
<animate attributeName="fill" from="colorA" to="colorB" dur="10s" repeatCount="indefinite" />
但这不允许我淡出颜色“A”。
任何帮助将不胜感激。
【问题讨论】:
您可以使用自定义 css 动画来实现:
@keyframes colorChange {
0%{fill:#ff0000}
50%{fill:#000}
100%{fill: #ff0000}
}
.box {
width:200px;
height:200px;
animation: colorChange 3s infinite;
}
只需将animation 属性应用于您想要更改填充的任何元素
http://jsfiddle.net/re8tn1o3/
【讨论】:
使用values 属性代替from 和to。
<svg>
<rect width="100%" height="100%">
<animate attributeName="fill" values="red;blue;red" dur="10s" repeatCount="indefinite" />
</rect>
</svg>
【讨论】: