SVG: Getting the position of an element relative to the page

前端 未结 3 1231
借酒劲吻你
借酒劲吻你 2021-02-02 00:13

I want to display an overlay (html div) when a user clicks on an element in an SVG diagram. To visualize the problem I\'m having, suppose that the SVG image has a horizontal row

3条回答
  •  滥情空心
    2021-02-02 00:29

    In case you haven't worked something out since March (and for anyone else having this problem), try getBoundingClientRect() on your SVG node.

    Returns a ClientRect object that gives you top, bottom, left, right, width, and height relative to the document. Was able to use this to position Twitter Bootstrap popovers (divs) next to SVG rects.

提交回复
热议问题