D3.js - why mouseover and mouse out fired for each child elements?

前端 未结 2 2088
醉酒成梦
醉酒成梦 2021-02-07 11:37

I use d3.js to generate a svg circle with a text logo in mid of the circle. Here is the svg result.


  

        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-07 12:33

    An alternate solution is to use mouseenter and mouseleave instead of mouseover and mouseout.

    mouseenter is similar to mouseover except that it is not triggered when the pointer (mouse) is moved from one of listener's (circle in this case) descendants' physical space (text in this case) to its own physical space.

    Same reasoning for 'mouseleave'

    Source: https://developer.mozilla.org/en-US/docs/Web/Events/mouseenter and https://developer.mozilla.org/en-US/docs/Web/Events/mouseleave

提交回复
热议问题