【问题标题】:Jquery parent div hide logic hides child dropdown menu on mouseoutJquery父div隐藏逻辑在鼠标悬停时隐藏子下拉菜单
【发布时间】:2010-07-23 10:03:31
【问题描述】:

我有一排带有“itemcontainer”类的div,在鼠标悬停时显示一组动作图标。其中一个动作图标有一个下拉菜单,其绝对位置会在鼠标悬停时显示。我试图解决的挑战是下拉菜单跨越项目容器,当您将鼠标向下移动到下拉菜单时,itemcontainer mouseout 逻辑启动并隐藏下拉菜单和项目容器。任何建议,下面的jquery代码。

  $(".itemcontainer").live("mouseover", function () {
        $(this).addClass("selecteditemcontainer");
        $(this).find(".actioncontainer").show();

    }).live("mouseout", function () {
            $(this).removeClass("selecteditemcontainer");
            $(this).find(".actioncontainer").hide();

    });

    $(".dropdown").live("mouseover", function () {
        $(this).find(".submenu").slideDown("fast").show();
        $(this).parent().mouseout(function () {
        }, function () {
            $(this).parent().find(".submenu").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up  
        });
    });

【问题讨论】:

    标签: jquery hide


    【解决方案1】:

    如果元素是子元素,您需要 mouseentermouseleave 事件,而不是 mouseovermouseout 事件,这在从父节点到子节点时不会触发。

    来自the mouseleave docs

    mouseleave 事件与 mouseout 处理事件冒泡的方式不同。如果在本例中使用了mouseout,那么当鼠标指针移出Inner 元素时,将触发处理程序。这通常是不受欢迎的行为。另一方面,mouseleave 事件仅在鼠标离开它所绑定的元素而不是后代元素时触发其处理程序。所以在这个例子中,当鼠标离开 Outer 元素而不是 Inner 元素时触发处理程序。

    【讨论】:

    • 关于为什么子菜单不会隐藏在mouselave上的任何想法?我可能有问题但没有看到。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 2014-09-05
    • 1970-01-01
    • 2013-08-27
    • 2016-12-19
    • 1970-01-01
    相关资源
    最近更新 更多