我正在尝试使用 javascript 更改 svg 图像颜色。这可能吗?我可以将它作为对象加载,然后以某种方式访问颜色/图像数据吗?
非常感谢每个回复或提示!
最佳答案
当然,这是一个示例(省略了标准 HTML 样板文件):
<svg id="svg1" xmlns="http://www.w3.org/2000/svg" style="width: 3.5in; height: 1in">
<circle id="circle1" r="30" cx="34" cy="34"
style="fill: red; stroke: blue; stroke-width: 2"/>
</svg>
<button onclick="circle1.style.fill='yellow';">Click to change to yellow</button>
关于javascript - 使用 JavaScript 更改 SVG 图像颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9872947/