在悬停其他元素时显示div,如果鼠标指针移出刚刚显示的div,则关闭它

时间:2018-01-05 12:56:25

标签: jquery megamenu

我正在尝试创建一个超级菜单,我想在显示菜单的特定声音时显示它。一旦显示了mega菜单(div),我想用鼠标(指针)保留它,并在指针移出div后关闭它。

这是我的菜单:

enter image description here

这是我的菜单,当你看到巨型菜单时,当你浏览“项目”链接时它会被打开:

enter image description here

目前,当我查看“项目”链接时,我可以显示菜单,但是当我将鼠标移出Mega菜单时,我不知道如何关闭它(div)

这是显示菜单的代码:

jQuery(document).ready(function(){
    jQuery("#menu-item-15").hover(
        function(){
            jQuery("#mega-menu-projects").show();
        }
    );
});

2 个答案:

答案 0 :(得分:0)

您可以使用鼠标悬停

jQuery(document).ready(function(){
    jQuery("#menu-item-15").mouseover(
        function(){
            jQuery("#mega-menu-projects").show();
        }
    );

    jQuery("#menu-item-15").mouseout(
        function(){
            jQuery("#mega-menu-projects").hide();
        }
    );
});

https://api.jquery.com/mouseover/

答案 1 :(得分:0)

试试这个(未经测试)

jQuery(document).ready(function(){
    jQuery( "#menu-item-15" ).mouseout(function() {
        jQuery("#mega-menu-projects").hide();
    })
    .mouseover(function() {
        jQuery("#mega-menu-projects").show();
    });
});

希望它对你有帮助