使用JavaScript更改SVG对象的高度和宽度 [英] Change height and width of SVG object using JavaScript

查看:233
本文介绍了使用JavaScript更改SVG对象的高度和宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单击按钮时更改svg对象的高度和宽度。我试过了,但是不起作用:

I want to change height and width of an svg object on a button click. I tried it but it doesn't work:

function modify() {
    document.getElementById('circle1').style.height = "10px";
    document.getElementById('circle1').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屋!

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