How to get Mid point of tag in svg using javascript

后端 未结 2 1486
北恋
北恋 2020-12-19 11:19

I am working in SVG tags using javascript. I tried to get group tag midpoint in svg. Is it possible to get mid point value of group tag using javascr

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-19 12:07

    If you want to get absolute middle point/position of g tag in screen:

    let el = document.getElementById("object_7")
    let midX = (el.getBoundingClientRect().left + el.getBoundingClientRect().right) / 2
    let midY = (el.getBoundingClientRect().top + el.getBoundingClientRect().bottom) / 2
    

    It also works for other svg elements.

提交回复
热议问题