[英]Force refresh of SVG gradient
I have an SVG which needs to be modified dynamically after page load.我有一个 SVG 需要在页面加载后动态修改。
Some elements are using fill="currentColor"
and others are using a gradient fill, which uses stop-color="currentColor"
in its stop
elements.一些元素使用
fill="currentColor"
而其他元素使用渐变填充,它在其stop
元素中使用stop-color="currentColor"
。 The idea is that I should be able to simply change the color
attribute of the parent SVG and all of the child elements should automatically change color too.这个想法是我应该能够简单地更改父 SVG 的
color
属性,并且所有子元素也应该自动更改颜色。
This works great for the elements which are using fill="currentColor"
, but the gradient-filled elements are not picking up the change.这对于使用
fill="currentColor"
的元素非常fill="currentColor"
,但渐变填充的元素没有接受更改。
Anything I can do to force a refresh?我能做些什么来强制刷新?
https://jsfiddle.net/chrisAtFundrise/bb9c8gnh/ https://jsfiddle.net/chrisAtFundrise/bb9c8gnh/
This might be a webkit
bug!这可能是一个
webkit
错误! Since the linearGradient
element is within a defs
element, and you have currentColor
used on your stop
element which is not being inherited.由于
linearGradient
元素位于defs
元素内,并且您在stop
元素上使用了currentColor
,而该元素未被继承。 You could also target the linearGradient
children <stop>
elements stop-color
attribute.您还可以针对
linearGradient
子元素<stop>
元素的stop-color
属性。
https://jsfiddle.net/bb9c8gnh/10/ https://jsfiddle.net/bb9c8gnh/10/
$("#button").on("click", function() {
$("svg").attr({color: "blue"});
$("svg linearGradient stop").eq(0).attr({"stop-color": "blue", offset:"100%"});
$("svg linearGradient stop").eq(1).attr({"stop-color": "blue"});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.