mouseenter/mouseleave 受到嵌套子对象的影响
我在文档上隐藏了一个控制面板(myNestContainer
)。我有一个名为 navMyNest
的按钮,当 mouseenter
发生时,会显示 myNestContainer
。这很好用。
问题是我希望用户能够浏览控制面板,但是鉴于 myNestContainer
中存在嵌套的 DIV 容器,一旦输入其中一个,mouseleave
生效并关闭控制面板。
这比 mouseenter
/mouseout
工作得更好,但仍然没有我想要的功能。
关于如何覆盖子对象以便控制面板在用户查看时保持打开状态有什么想法吗?
提前致谢。
$(document).ready(function() {
$("div#myNestContainer").hide();
});
$("div#navMyNest").live("mouseenter", function(event) {
$("div#myNestContainer").show();
});
$("div#myNestContainer").live("mouseleave", function(event) {
$("div#myNestContainer").hide();
});
I am hiding a control panel (myNestContainer
) on document ready. I have a button called navMyNest
that when mouseenter
occurs, shows the myNestContainer
. This works fine.
The issue is that I want the user to be able to explore the control panel, however given there are nested DIV containers in the myNestContainer
, as soon as one is entered, the mouseleave
take effect and the control panel closes.
This is working much better then mouseenter
/mouseout
, but still don't have the functionality I'd like.
Any thoughts on how to overrided the child objects so that the control panel stays open while the user is look through it?
Thanks in advance.
$(document).ready(function() {
$("div#myNestContainer").hide();
});
$("div#navMyNest").live("mouseenter", function(event) {
$("div#myNestContainer").show();
});
$("div#myNestContainer").live("mouseleave", function(event) {
$("div#myNestContainer").hide();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果鼠标移动到嵌套元素,请使用
event.latedTarget
保持父元素可见。Use
event.relatedTarget
to keep the parent element visible if the mouse moves to the nested element.我不得不诉诸很多丑陋的黑客才能让这种事情发挥作用。这也是特定于浏览器的黑客攻击。就我而言,我的嵌套元素中有 iframe 元素。
我必须使用延迟/超时,获取鼠标的 (x,y) 位置,并响应 mousemove 事件。
基本上,您必须定期检查,直到鼠标位于边界区域之外,然后删除元素。
我使用淡出效果来删除元素,以使延迟时间更加不明显。
将鼠标悬停在右上角的 Facebook“f”图标即可查看其实际效果:http://www2.highpoint.edu/< /a>
I had to resort to lots of ugly hacks to get this type of thing to work. And it was browser-specific hacks, too. In my case, I had iframe elements in my nested elements.
I had to use delays/timeouts, get the (x,y) position of the mouse, and respond to mousemove events.
Basically, you have to keep checking on regular intervals until mouse is outside bounding area, and then remove element.
I used a fade out effect to remove element to make lag time a little more unnoticeable.
See it in action by hovering of Facebook 'f' icon in top right corner: http://www2.highpoint.edu/
您可以使用jquery悬停功能来解决这个问题...
http://api.jquery.com/hover/< /a>
它基本上解决了您当前面临的问题。使用下面的代码
you can use jquery hover function to overcome the issue...
http://api.jquery.com/hover/
It basically handles the problem you are currently facing. Use the following piece of code