mouseenter/mouseleave 受到嵌套子对象的影响

发布于 2024-12-20 04:44:20 字数 700 浏览 6 评论 0原文

我在文档上隐藏了一个控制面板(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

别想她 2024-12-27 04:44:20

如果鼠标移动到嵌套元素,请使用 event.latedTarget 保持父元素可见。

$('#myNestContainer').mouseout(function(e)
{
    var evt = e || window.event;
    if (evt.relatedTarget != document.getElementById('navMyNest'))
    {
        $("#myNestContainer").hide();
    }
});

Use event.relatedTarget to keep the parent element visible if the mouse moves to the nested element.

$('#myNestContainer').mouseout(function(e)
{
    var evt = e || window.event;
    if (evt.relatedTarget != document.getElementById('navMyNest'))
    {
        $("#myNestContainer").hide();
    }
});
听不够的曲调 2024-12-27 04:44:20

我不得不诉诸很多丑陋的黑客才能让这种事情发挥作用。这也是特定于浏览器的黑客攻击。就我而言,我的嵌套元素中有 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/

夏有森光若流苏 2024-12-27 04:44:20

您可以使用jquery悬停功能来解决这个问题...

http://api.jquery.com/hover/< /a>

它基本上解决了您当前面临的问题。使用下面的代码

 $("div#myNestContainer").hover( 

    function () {
     $("div#myNestContainer").show(); 
    },

    function () { 
    $("div#myNestContainer").hide(); 
    }
);

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

 $("div#myNestContainer").hover( 

    function () {
     $("div#myNestContainer").show(); 
    },

    function () { 
    $("div#myNestContainer").hide(); 
    }
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文