问题
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