jquery mouseleave通过div下边框的效果
这让我抓狂。
有没有办法仅在将 div 穿过其底部边框时才触发 mouseleave jquery 效果?
也就是说,如果鼠标指针通过其他 3 个边框中的任何一个离开 div,则防止发生上述效果。
我想这一定是某种坐标问题,但位置和偏移对我来说都不是答案。
如果可以完成类似的事情,那么只要提供有关如何做到这一点的最微小的示例,我们将不胜感激。
如果已经提出(并回答)类似的问题,我们也将不胜感激任何重定向。
谢谢!
This is making me crazy.
Is there a way to fire a mouseleave jquery effect only if leaving the div through its bottom border?
That is, preventing said effect from taking place if the mouse pointer leaves the div through any of the other 3 borders.
I guess it must be a coordinates issue of some sort, but neither position not offset seem like the answer to me.
If something like that can be done, just the tiniest of examples on how to do it would be greatly appreciated.
If a similar question has already been asked (and answered) any redirections will be appreciated as well.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
怎么样:
http://jsfiddle.net/uqcU6/6/
How about this:
http://jsfiddle.net/uqcU6/6/
对于 HTML
、CSS
和 JavaScript
或演示,控制台< /em> 仅当鼠标离开
底部时才会出现输出
For HTML
and CSS
and JavaScript
or demo, a Console output will occur only when mouse leaves the bottom of the
<div>
快速的解决方案是将一个透明的 div 绝对定位到元素的底部,然后监听该 div 上的 mouseenter 来触发父 div 上的 mouseleave 。
The quick solution would be to put a transparent div absolute positioned to the bottom of the element and then listen for a
mouseenter
on that div to trigger themouseleave
on the parent div.如果您无法添加另一个 div,另一种解决方案是获取相关 div 的底部 y 坐标。并检查鼠标是否位于 mouseleave 事件中的下方。您可能需要检查 x1 < xm < x2,其中 x1 是 div 的左侧 x 坐标,x2 是 div 的右侧 x 坐标,xm 是鼠标的 x 坐标。
@kingjiv 用一个代码示例打败了我,但侧面检查可能会完善整个事情。
Another solution if you can't add another div would be to take the bottom y coordinates of the div in question. And check to see if the mouse was below that in the mouseleave event. You might have to check x1 < xm < x2, where x1 is the left x coordinate of your div and x2 is the right x coordinate of your div and xm is the x coordinate of your mouse.
@kingjiv beat me to it with a code-example, but the sidechecks might refine the whole thing.
最简单的解决方案是使用包装器 div 并将 mouseleave 事件分配给包装器。
http://jsfiddle.net/AlienWebguy/TDCgM/
Simplest solution is to use a wrapper div and assign the
mouseleave
event to the wrapper.http://jsfiddle.net/AlienWebguy/TDCgM/
在 mouseLeave 处理程序中添加一个条件语句,用于检查鼠标是否低于元素的底部。如果是,则鼠标很可能从底部边框退出。
例子:
});
Add a conditional statement inside your mouseLeave handler that checks whether the mouse is lower than the bottom of the element. If it is, the mouse most likely exited through the bottom border.
example:
});