Enclose the <rect>
within a <g>
element, then obtain a reference to the group, and finally invoke getBBox()
on it.
var bbox = document.getElementById("wrapper").getBBox();
alert("width=" + bbox.width + " height=" + bbox.height);
<svg>
<g id="wrapper">
<rect x="50" y="10" width="20" height="30" style="stroke: #000000; fill:none;"
transform="skewX(10)" />
</g>
</svg>
The rationale for wrapping the element in a group is that the bounding box provided by getBBox()
does not account for the transformation effects. It doesn't necessarily have to be a <g>
; any parent of the <rect>
would suffice as long no other child elements impact the boundaries.
Alternatively, you could utilize trigonometry as suggested by Stephen.