How to get the width of an svg:g element

前端 未结 2 1809
温柔的废话
温柔的废话 2020-12-02 22:21

I am currently working with an svg element in JavaScript. And I am new to this.

My question is that I have an svg element in which I have m

相关标签:
2条回答
  • 2020-12-02 22:31

    Try .getBoundingClientRect

    $('.my-class')[0].getBoundingClientRect().width;
    

    Demo http://jsfiddle.net/5DA45/

    0 讨论(0)
  • 2020-12-02 22:41

    I'd recommend getBBox (which is part of SVG 1.1) over getBoundingClientRect (which isn't):

    $('.my-class')[0].getBBox().width;
    

    Demo http://jsfiddle.net/TAck4/

    0 讨论(0)
提交回复
热议问题