gpt4 book ai didi

javascript - 需要禁用下拉菜单的淡出功能(仅)

转载 作者:行者123 更新时间:2023-11-28 07:01:58 25 4
gpt4 key购买 nike

我的移动模式菜单有问题。 onClick 它淡出。我想保留此设置,但我不希望它在单击下拉部分时淡出。这是链接:http://jsfiddle.net/zLLzrs6b/3/感谢您的帮助!

html:

<nav id="nav-wrap"> <a class="mobile-btn" href="#nav-wrap" title="Show navigation">Show Menu</a>
<a class="mobile-btn" href="#" title="Hide navigation">Hide Menu</a>
<ul id="nav" class="nav">
<li><a class="smoothscroll mobile" href="#about">about</a>
</li>
<li><a class="smoothscroll mobile" href="#documents">blog</a>
</li>
<li class="nav-item"><a href="#">dropdown</a>
<ul class="langop">
<li><a href="#">otion 1</a>
</li>
<li><a href="#">otion 2</a>
</li>
</ul>
</li>
</ul>
</nav>

CSS:

.langop {
display:none;
position: relative;
width:auto;
}
.nav-item:hover .langop {
display: block;
}

java:

var toggle_button = $("<a>", {
id: "toggle-btn",
html: "Menu",
title: "Menu",
href: "#"
});
var nav_wrap = $('nav#nav-wrap')
var nav = $("ul#nav");


nav_wrap.find('a.mobile-btn').remove();
nav_wrap.prepend(toggle_button);

toggle_button.on("click", function (e) {
e.preventDefault();
nav.slideToggle("fast");
});

if (toggle_button.is(':visible')) nav.addClass('mobile');
$(window).resize(function () {
if (toggle_button.is(':visible')) nav.addClass('mobile');
else nav.removeClass('mobile');
});

$('ul#nav li a').on("click", function () {
if (nav.hasClass('mobile')) nav.fadeOut('fast');
});

最佳答案

查看此demo

$('ul#nav > li > a').on("click", function () {
if (nav.hasClass('mobile'))
nav.fadeOut('fast');
});

关于javascript - 需要禁用下拉菜单的淡出功能(仅),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32056346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com