使用javascript更改SVG图像颜色 [英] Changing SVG image color with javascript
本文介绍了使用javascript更改SVG图像颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用javascript更改svg图像颜色。这可能吗?我可以将其作为对象加载,然后以某种方式访问颜色/图像数据。
I am trying to alter svg image colors with javascript. Is this possible? Can I load it as an object and then somehow have access to the color/image-data.
每个响应或提示都非常受欢迎!
Every respone or tip is highly appreciated!
推荐答案
当然,这是一个例子(省略标准HTML样板):
Sure, here is an example (standard HTML boilerplate omitted):
<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更改SVG图像颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文