简体   繁体   English

使用 JavaScript 更改 SVG 对象的高度和宽度

[英]Change height and width of SVG object using JavaScript

I want to change height and width of an svg object on a button click.我想在单击按钮时更改 svg 对象的高度和宽度。 I tried it but it doesn't work:我试过了,但它不起作用:

function modify() {
    document.getElementById('circle1').style.height = "10px";
    document.getElementById('circle1').style.width = "10px";        
}

In SVG width and height of <rect> elements are attributes and not CSS properties so you'd need to write在 SVG 中<rect>元素的宽度和高度是属性而不是 CSS 属性,因此您需要编写

document.getElementById('cercle1').setAttribute("height", "10px");

similarly for the width.宽度类似。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM