Change height/width of object SVG using JavaScript

走远了吗. 提交于 2019-12-22 02:01:29

问题


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";        
}

回答1:


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");

similarly for the width.



来源:https://stackoverflow.com/questions/26392165/change-height-width-of-object-svg-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!