gpt4 book ai didi

javascript - 如何关闭响应式菜单,单击导航外部

转载 作者:行者123 更新时间:2023-12-01 03:09:57 27 4
gpt4 key购买 nike

您好,我的问题是,我有一个菜单,一个带有 Bootstrap 的响应式菜单,我想关闭桌面上响应式 View 上的菜单,这很好,但在响应式 View 上,我希望当我单击任何区域的导航菜单外部时,它应该关闭,我的导航代码如下

<!-- Navigation -->

<nav id="navigation-sticky" class="white-nav b-shadow">

<!-- Navigation Inner -->

<div class="nav-inner">

<div class="logo">

<!-- Navigation Logo Link -->

<a href="#home" class="scroll">

<!-- Your Logo -->

<img src="" class="site_logo" alt=""/><br>

</a>

</div>

<!-- Mobile Menu Button -->

<a class="mobile-nav-button colored"><i class="fa fa-bars"></i></a>

<!-- Navigation Menu -->

<div class="nav-menu clearfix ">

<ul class="nav uppercase oswald">

<li><a href="#home" class="scroll">home</a></li>

<li class="dropdown-toggle nav-toggle" ><span href="#about" class="scroll">About App<b data-toggle="dropdown"></b></span>

<!-- DropDown Menu -->

<ul class="dropdown-menu uppercase gray-border clearfix">

<li><a href="#works" class="scroll">HOW DOES IT WORK?</a></li>
<li><a href="#features" class="scroll">Features</a></li>
<li><a href="#what-we-do" class="scroll">APP FLOW</a></li>
<li><a href="#faq" class="scroll">F.A.Q</a></li>

</ul>

<!-- End DropDown Menu -->

</li>



<li><a href="#portfolio" class="scroll">Service Types</a></li>

<li><a href="#skills" class="scroll">Cities</a></li>

<li><a href="#prices" class="scroll">Rates</a>

</li>

<li><a href="#download" class="scroll">Download</a></li>



<li class="dropdown-toggle nav-toggle" ><span aria-expanded="false" aria-haspopup="true" role="button" data-toggle="dropdown" class="dropdown-toggle scroll">Become a Driver</span>

<!-- DropDown Menu -->

<ul class="dropdown-menu uppercase gray-border clearfix">

<li><a href="#" class="scroll">Signup</a></li>
<li><a href="#" class="scroll">Flyer</a></li>


</ul>

<!-- End DropDown Menu -->

</li>

<li><a href="#" class="scroll">login</a></li>

<li><a href="#contact" class="scroll">contact</a></li>

</ul>

</div><!-- End Navigation Menu -->

</div><!-- End Navigation Inner -->

</nav><!-- End Navigation -->

我使用此脚本关闭菜单,它关闭菜单,但通过双击而不是单击打开菜单

$('html').click(function() {
$('#menu').hide();
});

最佳答案

我认为这可能适合你:

$(document).mouseup(function (e)
{
var container = $(".nav-menu");

if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
container.css("display","none");
}
});

更新:试试这个

var container = $(".nav-inner div.nav-menu, .mobile-nav-button");

if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
$(".nav-inner div.nav-menu").slideUp();
}

关于javascript - 如何关闭响应式菜单,单击导航外部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33645509/

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