Finding Offset Position of SVG Element

后端 未结 3 2174
栀梦
栀梦 2020-12-29 23:22

I\'ve run into this problem a lot with D3. A lot of the time I like to overlay HTML objects over my SVG.

My current strategy is creating an empty DIV next to the SV

3条回答
  •  没有蜡笔的小新
    2020-12-29 23:39

    Extending James Lai's answer to support modern versions of IE:

    function getVpPos(el) {
        if(el.parentNode.nodeName === 'svg') {
            return el.parentNode.getBoundingClientRect();
        }
        return getVpPos(el.parentNode);
    }
    

    Note: parentElement is changed to parentNode and tagName is changed to nodeName.

提交回复
热议问题