且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

D3.js:如何获得任意元素的计算宽度和高度?

更新时间:2022-11-15 09:41:45

对于SVG元素



使用像 selection.node()。getBBox()这样的值,你会得到像

For SVG elements

Using something like selection.node().getBBox() you get values like

{
    height: 5, 
    width: 5, 
    y: 50, 
    x: 20
} 



对于HTML元素



使用 selection.node()。getBoundingClientRect()