html - 为什么这个 SVG 滤镜动画在 Edge 或 Chrome 中不起作用?

标签 html google-chrome svg css-animations microsoft-edge

我创建了这个 SVG 和滤镜动画。盒子应该不断改变颜色。

@keyframes hue {
  from {
    filter: hue-rotate(0deg);
  }

  to {
    filter: hue-rotate(-360deg);
  }
}

.hex {
    fill-opacity: 1.0;
    animation: hue 5s infinite linear;
}
<svg id="color-fill" xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="150" viewBox="0 0 300 300" xmlns:xlink="http://www.w3.org/1999/xlink">
  
  <polygon class="hex" points="0,0 300,0 300,300 0,300" fill="red"></polygon>
  
</svg>

在 Firefox 62 中这有效。

在 Edge 17 和 Chrome 69 中,我看到一个红色矩形。

为什么这在 Edge 和 Chrome 中不起作用?

最佳答案

正如 @Kaiido 在评论中提到的,Chrome/Edge 目前不支持单个 SVG 元素上的 CSS 过滤器,但将过滤器应用于整个 SVG 可以在两种浏览器上使用,如您所见这个例子:

@keyframes hue {
  from {
    filter: hue-rotate(50deg);
  }

  to {
    filter: hue-rotate(-360deg);
  }
}

.hex {
    fill-opacity: 1.0;
    animation: hue 5s infinite linear;
    filter: hue-rotate(50deg);
}
<svg class="hex" id="color-fill" xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="150" viewBox="0 0 300 300" xmlns:xlink="http://www.w3.org/1999/xlink">
  
  <polygon points="0,0 300,0 300,300 0,300" fill="red"></polygon>
  
</svg>

关于html - 为什么这个 SVG 滤镜动画在 Edge 或 Chrome 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52693598/

相关文章:

javascript - 无法让 forEach 在 IE 上正常工作

css - Chrome 大小错误还是我的误解?

javascript - 单击超链接向下滚动屏幕

html - p 标签内可调整大小的 img,其宽度大于容器

javascript - chrome 上奇怪的本地存储项目

google-chrome - chrome 调度轮事件

html - SVG Sprites - 如果元素比图像更高更宽怎么办?

html - 如何将 HTML 元素放置在内联 SVG 上

html - 当我使用外部样式表时,Firefox SVG 图像被截断

html - 动态对齐 :after according to parent length