使用jQuery检查mouseleave()上光标所在的元素? [英] Check what element the cursor is on upon mouseleave() with jQuery?
问题描述
我有一组列表元素(< li>
在< ul>
内)像这样的图表上的气泡,气泡是< li>
元素:
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
- Moving the mouse from bubble #1 to the grid
- 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屋!