I want to read:
width
,height
,x
,y
measurementsfor a particular SVG element.
I suppose that easiest way to go about this is to fetch the minimum bounding box first and read it's properties.
How can I access this?
If you have a reference to the DOM node, use
svgNode.getBoundingClientRect()
https://developer.mozilla.org/en-US/docs/DOM/element.getBoundingClientRect
Edit: SVG Edit has a method to return currently selected elements:
svgCanvas.getSelectedElems()
so in the above example:
svgNode = svgCanvas.getSelectedElems()[0];
svgNode.getBoundingClientRect();
Please see http://granite.sru.edu/~ddailey/svg/BBox0M.svg for the example and answer.
In brief, this code works for me in Chrome:
<script>
function foo(evt)
{
console.log(evt.target.getBBox());
}
</script>
<svg>
<circle onclick="foo(evt)" r="20%" cx="50%" cy="50%"/>
</svg>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With