您好,请问我的Jquery函数可以帮助我吗?显示我的sidenav时,如果我单击链接,则侧边栏将保持打开状态,并且没有内容显示。我可能会想念什么吗?
var $hamburger = $(".hamburger"),
$menuWrap = $('.menu-wrap');
$hamburger.on("click", function () {
$hamburger.toggleClass("is-active");
// Do something else, like open/close menu
$menuWrap.toggleClass('menu-show');
$hamburger.click(function(){
$(this).next().slideToggle(300);
});
});
对不起,我将缺少的代码与整个html代码一起添加。
<div class="d-md-none">
<div class="d-flex justify-content-end">
<div class="hamburger hamburger--elastic">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</div>
<div class="container">
<div class="row d-flex justify-content-center">
<div class="menu-wrap">
<div class="col-12 menu-sidebar display-6">
<ul class="menu navbar-nav ml-auto">
<li class="nav-item"><a href="./index.php">ACCUEIL</a></li>
<li class="nav-item"><a href="#portfolio">PORTFOLIO</a></li>
<li class="nav-item"><a href="#contact">CONTACT</a></li>
<li class="nav-item"><a href="#about">QUI EST RABAH</a></li>
</ul>
</div>
<hr class="light-yellow my-5">
<div class="col-12 d-flex justify-content-between wow fadeInDown">
<a href="http://www.linkedin.com/in/rabah-a-44062b5b" data-delay="50" target="new"><i class="fab fa-linkedin-in fa-2x text-jaune"></i></a>
<a href="https://www.instagram.com/rabahbook/?hl=fr" data-delay="50" target="new"><i class="fab fa-instagram fa-2x text-jaune"></i></a>
<i class="fab fa-behance fa-2x text-jaune"></i>
<i class="fab fa-facebook-f fa-2x text-jaune"></i>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
我找到了解决方案,但是一个链接不起作用。目前它起作用。感谢您的帮助。
var $hamburger = $(".hamburger"),
$menuWrap = $('.menu-wrap');
function sideNavBar() {
$hamburger.on("click", function (e) {
$hamburger.toggleClass("is-active");
// Do something else, like open/close menu
$menuWrap.toggleClass('menu-show');
$hamburger.click(function () {
$(this).next().slideToggle(300);
});
e.stopPropagation();
return false;
});
$('*:not(.hamburger)').on('click', function () {
$menuWrap.removeClass('menu-show');
$hamburger.removeClass('is-active');
});
}
sideNavBar();