使用JavaScript更改对象SVG的高度/宽度 [英] Change height/width of object SVG using JavaScript
本文介绍了使用JavaScript更改对象SVG的高度/宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望在按钮中单击时更改高度或宽度。我试试这个但不行:
I want change height or width when a click in a button. I try this but not work:
function modify(){
document.getElementById('cercle1').style.height = "10px";
document.getElementById('cercle1').style.width = "10px";
}
推荐答案
在SVG的宽度和高度< rect>
元素是属性,而不是CSS属性,因此您需要编写
In SVG width and height of <rect>
elements are attributes and not CSS properties so you'd need to write
document.getElementById('cercle1').setAttribute("height", "10px");
类似的宽度。
这篇关于使用JavaScript更改对象SVG的高度/宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文