Get bounding box for SVG path using jQuery

前端 未结 5 1625
北荒
北荒 2020-12-16 17:22

I want to get the getBBox() for svg path in jquery. i tried like this

$(\"#\"+ path id)[0].getBBox() -> returns x=0,y=0,width=0,height=0

5条回答
  •  悲&欢浪女
    2020-12-16 17:46

    I too am having a hard time getting the JQuery syntax to work for me. This returned Uncaught TypeError: Object [object Object] has no method 'getBBox':

    console.log($("#testtext").getBBox().width);
    

    ... because I had omitted the array index (thanks @Christian Vielma, below)!

    However standard Javascript worked for me and I was able to display the width of the (in my case) RECT in the Chrome console:

    console.log(document.getElementById("testtext").getBBox().width);
    

    So you might try that instead.

提交回复
热议问题