Show d3 node text only on hover

后端 未结 1 1743
猫巷女王i
猫巷女王i 2021-02-05 10:06

I\'m trying to only show the node text on mouseover. When I mouseover the node, I have the opacity for the svg circle changing, but only the text for the first node showing up.

相关标签:
1条回答
  • 2021-02-05 10:31

    If you use d3.select you're searching the entire DOM for <text> elements and selecting the first one. To select specific text nodes you either need a more specific selector (e.g. #textnode1) or you need to use a subselection to constrain the selection under a particular parent node. For example, if the <text> element lived directly under the node in your example you could use:

    .on('mouseover', function(d){
        var nodeSelection = d3.select(this).style({opacity:'0.8'});
        nodeSelection.select("text").style({opacity:'1.0'});
    })
    
    0 讨论(0)
提交回复
热议问题