Jquery 如何在单击div时显示弹出菜单
我在一个网站上工作,当屏幕像手机一样小时,它会创建一个悬停菜单按钮 我的悬停菜单按钮和菜单的html代码如下所示。在classJquery 如何在单击div时显示弹出菜单,jquery,html,menu,Jquery,Html,Menu,我在一个网站上工作,当屏幕像手机一样小时,它会创建一个悬停菜单按钮 我的悬停菜单按钮和菜单的html代码如下所示。在classmnav按钮lt768中,按钮出现在classmobile nav wrap lt768中,并且class具有菜单本身 我的问题是我从一个网站上得到了这个例子 我不知道当用户在类mnav按钮lt768中单击时,他们是如何得到弹出菜单的 当在div classmnav按钮lt768中单击时,如何获得一个菜单来显示 还请注意,当用户单击div 这是Html <div
mnav按钮lt768
中,按钮出现在classmobile nav wrap lt768
中,并且class具有菜单本身
我的问题是我从一个网站上得到了这个例子
我不知道当用户在类mnav按钮lt768
中单击时,他们是如何得到弹出菜单的
当在div classmnav按钮lt768
中单击时,如何获得一个菜单来显示
还请注意,当用户单击div
这是Html
<div class="mnav-button lt768"></div>
<div class="mobile-nav-wrap lt768">
<nav class="mobile-nav">
<div class="close-btn"></div>
<a href="#" class="home">
<span>Home</span>
</a>
<a href="#">
<span>Company</span>
</a>
<a href="#">
<span>Work</span>
</a>
<a href="#">
<span>Space</span>
</a>
</nav>
</div>
所以这仍然不起作用,我上传了这个网站,所以你们都可以在这里访问它kewsplus.com/testing
你们想要这样的效果吗
HTML:
在上,我们使用一段简单的jQuery风格的JavaScript来检测移动导航按钮的点击(或触摸),并使用该事件从主体中添加/删除类。然后,在CSS中,我们使用这个类更改来隐藏/显示移动导航
Javascript:
// We're going to use the "touchstart" event since we're aiming this as touch devices, not desktop devices
$('body').on('touchstart','.mnav-btn',function(event){
// let's prevent the default action
event.preventDefault();
// trigger the class change
$('body').addClass('mnav-open');
});
// then, the close button
$('.mnav').on('touchstart','.close-btn',function(event){
event.preventDefault();
$('body').removeClass('mnav-open');
});
// OR -- if you don't want your site to require the close button, and the nav button will always be present, you can use this instead
$('body').on('touchstart','.mnav-btn',function(event){
event.preventDefault();
// Will add the class if it doesn't exist, and remove it if it does
$('body').toggleClass('mnav-open');
});
基本样式:
.mnav {
// put design styles here
display:none; // keeps the nav hidden until the class .mnav-open is added to body
}
.mnav-open .mnav {
display:block;
}
应该可以了。您需要jQuery(或Javascript)来实现这一点。你可能想看看这里,你不需要javascript,这里只是一个CSS示例-所以这仍然不起作用我上传了网站,所以你们都可以在这里访问它
// We're going to use the "touchstart" event since we're aiming this as touch devices, not desktop devices
$('body').on('touchstart','.mnav-btn',function(event){
// let's prevent the default action
event.preventDefault();
// trigger the class change
$('body').addClass('mnav-open');
});
// then, the close button
$('.mnav').on('touchstart','.close-btn',function(event){
event.preventDefault();
$('body').removeClass('mnav-open');
});
// OR -- if you don't want your site to require the close button, and the nav button will always be present, you can use this instead
$('body').on('touchstart','.mnav-btn',function(event){
event.preventDefault();
// Will add the class if it doesn't exist, and remove it if it does
$('body').toggleClass('mnav-open');
});
.mnav {
// put design styles here
display:none; // keeps the nav hidden until the class .mnav-open is added to body
}
.mnav-open .mnav {
display:block;
}