SVG onmouseover for group with overlapping elements occurs twice

后端 未结 2 820
抹茶落季
抹茶落季 2021-01-06 12:30

When attaching a function to the onmouseover event for an SVG group ..., the event occurs once, each time the pointer enters to

2条回答
  •  我在风中等你
    2021-01-06 12:58

    You can check which element the mouse WAS in. If its part of a certain group, then ignore the mouse event. Like so:

    function isRelated(e) { 
        if ($(e.relatedTarget).closest('#rect1,#rect2).length == 0) { //http://api.jquery.com/closest/
            return false;
        }
        return true;
    }
    

    Here is a fiddle: http://jsfiddle.net/pFTfm/57/

提交回复
热议问题