使用 jQuery 检查 mouseleave() 时光标所在的元素? [英] Check what element the cursor is on upon mouseleave() with jQuery?

查看:22
本文介绍了使用 jQuery 检查 mouseleave() 时光标所在的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组列表元素(

  • 位于
      中)在像这样的图表上以气泡形式排列,其中气泡是
    • 元素:

      I have a set of list elements (<li> within a <ul>) laid out as bubbles on a chart like this, where the bubbles are the <li> elements:

      http://i.stack.imgur.com/PR7vR.png

      我希望能够检测到

      1. 将鼠标从气泡 #1 移动到网格
      2. 将鼠标从气泡 #1 直接移动到另一个气泡,例如气泡 2
      1. Moving the mouse from bubble #1 to the grid
      2. Moving the mouse from bubble #1 directly to another bubble, such as bubble 2

      我试图在 .mouseleave() 中使用 $(this) 甚至是一个气泡,但它注册了你要离开的元素而不是您当前悬停的元素.

      I've attempted to use $(this) in the .mouseleave() even for a bubble, but it registers the element that you're leaving rather than the element that you're currently hovering.

      关于如何在 mouseleave() 上获取鼠标移动到的元素的任何想法?

      Any ideas on how to get the element that the mouse is moving onto upon mouseleave()?

      推荐答案

      你需要使用 event.toElement ||e.relatedTarget:

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

      (编辑为注意|| e.relatedTarget,以确保浏览器兼容性)

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

      这篇关于使用 jQuery 检查 mouseleave() 时光标所在的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆