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

前端 未结 3 1230
借酒劲吻你
借酒劲吻你 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:27

    jQuery's position() does not work well for SVG elements. There is a ticket for that.

    You can use the native SVG method getBBox() to get the position of a SVG element.

    Example

    $('svg circle')[0].getBBox();
    

提交回复
热议问题