停止我的下拉菜单出现在加载时,我已经点击了导航链接
Stop my dropdown appearing onload when I have clicked on nav link
我似乎找不到合适的搜索词来回答这个问题!我的导航栏中有一个下拉菜单出现在鼠标悬停时,如果我点击导航链接转到另一个页面,而我的鼠标停留在同一位置,我该如何阻止它加载下拉菜单?我希望它是这样的站点:
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事件
相关文章:
- 使用jQuery库Packey来制作卡片布局,我可以用导航链接重新订购
- (html/css/javascript)试图使导航栏中的“当前页面”链接变成不同的颜色
- 导航到链接9000次
- 当主导航链接悬停时,在侧菜单中显示链接
- Angular UI&引导程序:点击链接时折叠移动导航栏
- 单击链接时折叠响应式导航
- 禁用导航链接上的聚焦行为
- 第二个引导程序导航栏链接打开第一个(错误的)导航栏;jquery
- 在没有服务器端脚本的情况下跨多个页面链接导航栏
- 与 AJAX 的可链接导航
- 在内联tinyMCE中保留超链接导航
- 共享Web工作者是否在单个页面重新加载、链接导航中保持不变
- 如何判断一个Angularjs页面是通过刷新加载的还是通过链接导航的
- HTML
- 动画锚链接导航
- 从另一个html中的超链接导航到页面中的特定选项卡(使用dojo tabcontainer)
- React.js——LinkContainer.阻止链接导航
- 创建一个链接导航到谷歌地图上的地图标记
- jQuery链接导航功能
- 自定义链接导航的谷歌搜索快捷方式