How does one get the height/width of an SVG group element?

前端 未结 3 2077
独厮守ぢ
独厮守ぢ 2020-12-03 05:17

I need to know the width and height of a SVG element? Im trying to use the following:

$(\'g#myGroup\').height()

...but the result is alway

3条回答
  •  没有蜡笔的小新
    2020-12-03 05:27

    I wasn't able to get any of the answers above to work, but did come across this solution for finding it with d3:

    var height = d3.select('#myGroup').select('svg').node().getBBox().height;
    var width = d3.select('#myGroup').select('svg').node().getBBox().width;
    

    getBBox() here will find the actual width and height of the group element. Easy as that.

提交回复
热议问题