Check what element the cursor is on upon mouseleave() with jQuery?

前端 未结 2 1081
無奈伤痛
無奈伤痛 2021-01-07 16:42

I have a set of list elements (

  • within a
      ) laid out as bubbles on a chart like this, where the bubbles are the
  • 相关标签:
    2条回答
    • 2021-01-07 17:28

      If you can use ordinarey javascript, every event (e) mouse over and mouse out has an e.relatedTarget in most browsers. IE before #9 has event.toElement and event.fromElement, depending on if you are listening to a mouseover or mouseout.

      somebody.onmouseout=function(e){
        if(!e && window.event)e=event;
        var goingto=e.relatedTarget|| event.toElement;
        //do something
      }
      somebody.onmouseover=function(e){
        if(!e && window.event)e=event;
        var comingfrom=e.relatedTarget|| e.fromElement;
        //do something
      }
      
      0 讨论(0)
    • 2021-01-07 17:44

      You need to use event.toElement || e.relatedTarget:

      $('li').mouseleave(function(e)
      {
          // new element is: e.toElement || e.relatedTarget
      });
      

      (Edited to note || e.relatedTarget to ensure browser compatibility)

      0 讨论(0)
    提交回复
    热议问题