使用 javascript 更改 SVG 图像颜色 [英] Changing SVG image color with javascript

查看:29
本文介绍了使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆