停止我的下拉菜单出现在加载时,我已经点击了导航链接

Stop my dropdown appearing onload when I have clicked on nav link

本文关键字:链接 导航 下拉菜单 我的 加载      更新时间:2023-09-26

我似乎找不到合适的搜索词来回答这个问题!我的导航栏中有一个下拉菜单出现在鼠标悬停时,如果我点击导航链接转到另一个页面,而我的鼠标停留在同一位置,我该如何阻止它加载下拉菜单?我希望它是这样的站点:

https://www.reiss.com/rw/womens/

如果我把鼠标悬停在"women"上,下拉菜单就会出现,如果我点击"women",它会把我带到那个页面,但是下拉菜单会消失,直到我把鼠标移开并回到它上面。目前,在我的代码中,当我点击下拉菜单时,如果我的鼠标没有移动,它会在页面加载时出现。

var stop = true;
var hovered;
var timeout;
$('.nav').hover(
    function(){
        clearTimeout(timeout);
        stop = true;
        hovered = this;
        timeout = setTimeout(function(){
        if($(hovered).hasClass('nav_menu_link_drop')){
            $('.content').css('z-index',0);
            $(hovered).next('.content').css('z-index',5);        
            $(hovered).next('.content').slideDown(350);
            timeout = setTimeout(function(){
                $('.content').not($(hovered).next('.content')).slideUp(350);  
            },200);
        }
        else
            $('.content').slideUp(350);    
        },400);
    },
    function(e){
        stop = false;
        clearTimeout(timeout);
        setTimeout(function(){
            if(!stop)
                $('.content').slideUp(350);
        },500);
    }
);
$('.content').hover(
    function(){
        stop = true;    
    },
    function(){
    }
);
$('#nav_menu').hover(
    function(){
    },
    function(){
        timeout = setTimeout(function(){
            $('.content').slideUp(350);
        },200);
    }
);

这可能会得到您想要的结果。

$('.nav').mouseeter(
    function(){
        clearTimeout(timeout);
        stop = true;
        hovered = this;
        timeout = setTimeout(function(){
        if($(hovered).hasClass('nav_menu_link_drop')){
            $('.content').css('z-index',0);
            $(hovered).next('.content').css('z-index',5);        
            $(hovered).next('.content').slideDown(350);
            timeout = setTimeout(function(){
                $('.content').not($(hovered).next('.content')).slideUp(350);  
            },200);
        }
        else
            $('.content').slideUp(350);    
        },400);
    },
    function(e){
        stop = false;
        clearTimeout(timeout);
        setTimeout(function(){
            if(!stop)
                $('.content').slideUp(350);
        },500);
    }
);
https://api.jquery.com/mouseenter/

这样,当你进入导航栏时触发,而不是当你将鼠标悬停在它上面时。

我很难理解你的代码。但是你可能还需要使用mouseleave事件

相关文章: