getBBox() returns nothing for rect or path

試著忘記壹切 提交于 2019-12-11 02:05:50

问题


Please refer below rect code.

<rect id="container_svg_ChartArea" x="146.8" y="20" width="633.2" height="414" fill="White" stroke-width="1" stroke="Gray"></rect>

i tried get the rectangle bounding box value it returns nothing i.e."0" for x=0,y=0,width=0,height=0

$("#container_svg_ChartArea")[0].getBBox()

but when i get the attribute for x/y/width/height it returns some value

$("#container_svg_ChartArea").attr("x") ->value returned.

same for path element as well as rectangle element.

what is going wrong?

no solution provide here.

how to get bounding box or rect (getBBox()) for svg path in jquery

thats why i created another thread. it is not duplicate thread.

Thanks,

Siva


回答1:


Look this example on how to get and manage the bounding box of svg elements

http://www.janvas.com/illustrators_designers_developers/projects/janvas2D_web/examples_EN.php?exampleName=ufo_animation_EN

in general

var svgElement = document.getElementById('the id of your element');
bbox = svgElement.getBBox();

console.log( bbox.x ) ;
console.log( bbox.y ) ;
console.log( bbox.width ) ;   
console.log( bbox.height ) ; 


来源:https://stackoverflow.com/questions/16393361/getbbox-returns-nothing-for-rect-or-path

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