Get dimension of a path in SVG

后端 未结 2 872
萌比男神i
萌比男神i 2020-12-09 09:03

I need to get the dimension on the screen of a in a SVG from JavaScript.

I do not have any \"transformation\" or \"scaling\" (transform, scale) on my SVG.

2条回答
  •  太阳男子
    2020-12-09 09:28

    First off all, keep in mind that path cannot have a width. Its a set of coords. The browser uses that info along with the drawing method to connect the coords and create a visible shape.

    Secondly, the bounding box is a snapshot of when the SVG was rendered. That is why you don't get the updated width on resize.

    A workaround I guess would be to get the width of the conatiner element to the SVG (div or something else).

    Maybe some of the libraries may provide some utility method to figure this out.

提交回复
热议问题