css - SVG 动画颜色过渡

标签 css animation svg

大家好,我正在尝试使用 SVG 制作一个矩形,其中使用 css 动画改变背景颜色。它在 chrome 中工作,但在 Firefox 或 IE 中不工作,是否有解决此问题或解决方案的方法?

这里以 fiddle 为例

HTML代码

<svg viewBox="0 0 202 197"
    xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
<defs>
<linearGradient y2="0" x2="1" y1="1" x1="1" id="green">
  <stop offset="0" stop-opacity="0.99609" stop-color="#027d07"/>
  <stop offset="1" stop-opacity="0.99609" stop-color="#1ff026"/>
</linearGradient>
<linearGradient id="red" x1="1" y1="1" x2="1" y2="0">
  <stop offset="0" stop-opacity="0.98828" stop-color="#8a0f04"/>
  <stop stop-color="#ff5454" stop-opacity="0.99609" offset="1"/>
</linearGradient>
</defs>
<rect x="0" y="0" width="50%" height="50%" class="red">
</rect>

CSS 代码

    /* Standard syntax Chrome*/
@-webkit-keyframes pulseRed {
    from {fill:url(#green)}
    to {fill:url(#red)}
}
/* Standard syntax IE and Firefox this is done differently 
because IE and Firefox does not support animation for gradient*/
@keyframes pulseRed {
  from {fill:url(#green)}
  to {fill:url(#red)}
}
.red
{
 -webkit-animation: pulseRed 2s infinite;
  -moz-animation: pulseRed 2s infinite;
    -ms-animation: pulseRed 2s infinite;
        animation: pulseRed 2s infinite;
}

要在IE和Firefox上添加,它们都显示一个黑框

jsFiddle 链接

http://jsfiddle.net/cyj89/zPuGz/

最佳答案

您需要为各自的浏览器使用供应商前缀

试试这个

.red{
-webkit-animation: pulsered 2s infinite;
   -moz-animation: pulsered 2s infinite;
    -ms-animation: pulsered 2s infinite;
        animation: pulsered 2s infinite;

}

关于css - SVG 动画颜色过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24259718/

相关文章:

Android同心圆缩放动画

text - 使用@font-face 时,SVG 文本边界框因浏览器而异?

javascript - 单击它后更改div css

CSS - 样式水平线

CSS:在表单上的最后一个控件之后放置一个提交按钮

ios - iOS 5.1 中的 SVG 滞后于 @2x PNG

vector - SVG 到 VML - 如何?

javascript - 带有透明三 Angular 形的下拉菜单(需要帮助)

html - 纯CSS设置动画进度百分比

ios - 仅在用户滚动时从 willDisplayCell 动画单元格,而不是在 reloadData 之后