使用JS更改SVG的渐变
本文介绍了使用JS更改SVG的渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过更改stop-color
属性来更改以下SVG元素中渐变的停止颜色,但不起作用:
<svg><defs>
<linearGradient gradientTransform="rotate(90)">
<stop offset="40%" stop-color="purple" id="firstGradient"/>
<stop offset="100%" stop-color="red" id="secondGradient"/>
</linearGradient>
</defs>
<Here's a long line of picture>
</svg>
我正在使用以下脚本语句尝试更改停止颜色:
document.getElementById("firstGradient").stopColor ="red";
我也尝试过document.getElementById("firstGradient").attr.stop-color = "red";
。
这两种方法都不管用。如何更改停止颜色?
推荐答案
您是否尝试过:
document.getElementById("firstGradient").style.stopColor ="red";
这篇关于使用JS更改SVG的渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,