Get width of d3.js SVG text element after it's created

后端 未结 3 1617
梦毁少年i
梦毁少年i 2021-02-19 00:43

I\'m trying to get the widths of a bunch of text elements I have created with d3.js

This is how I\'m creating them:

var nodesText = svg.sel         


        
3条回答
  •  清酒与你
    2021-02-19 01:08

    You can use getBoundingClientRect()

    Example:

    .style('top', function (d) {
         var currElemHeight = this.getBoundingClientRect().height;
    }
    

    edit: seems like its more appropriate for HTML elements. for SVG elements you can use getBBbox() instead.

提交回复
热议问题