[英]how to close the menu with a Click outside in jquery on iPad
I got a menu that opens correctly and close correctly when you touch the menu on a iPad. 当您触摸iPad上的菜单时,我得到了可以正确打开和关闭的菜单。 thats fine, but i also want to close the menu, when you touch outside the menu. 没关系,但是当您触摸菜单外时,我也想关闭菜单。 it works when you touch a picture and a link, but it doesnt work when you touch anywhere else. 它在您触摸图片和链接时有效,但在您触摸其他任何地方时均无效。
here its my code: 这是我的代码:
HTML : HTML:
<nav onclick="" class="acconicon">
<nav class="accon">
<figure class="acmlogo"></figure>
<h5 class="acconh5">Hovedmenu</h5>
<ul class="sbm3">
<a href="index.php"><li class="acfront">Forside </li></a>
<a href="news.php"><li class="acnews">Nyheder </li></a>
<a href="artists.php"><li class="acartists">Artister</li></a>
<a href="releases.php"><li class="acreleases">Udgivelser</li></a>
<a href="live.php"><li class="aclive">Live</li></a>
<a href="video.php"><li class="acvideo">Videoer </li></a>
<a href="interaction.php"><li class="accomp">Konkurrencer</li></a>
<a href="remix.php"><li class="acremix">Remix</li></a>
</ul>
</nav>
</nav>
Script: 脚本:
$('html').click(function() {
$('.accon').hide();
});
$('.acconicon').click(function(event){
event.stopPropagation();
});
$('.acconicon').click(function(event){
$('.accon').toggle();
});
I think you just need to use not selector of JQuery
. 我认为您只需要使用JQuery
选择器即可。 I created a simple code that you should try. 我创建了一个简单的代码,您应该尝试一下。
$('*:not(.acconh5,sbm3,sbm3 > a)').click(function() {
$('.accon').hide();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.