Js代码:
$(document).click(function () {
$('.hide-menu').click(function (event) {
event.preventDefault();
$('body').toggleClass('hide-sidebar');
});
});-The hamBurger菜单有一个永久的类隐藏菜单.-默认情况下,body标记中存在“隐藏-侧栏”类。
发布于 2020-04-08 07:44:25
如果删除$(document).click()部分,代码就能工作。您也不需要preventDefault() (但是如果将它留在代码中,它也能工作)
$('.hide-menu').click(function(event) {
$('body').toggleClass('hide-sidebar');
});.hide-sidebar nav {
display: none;
}
/*
These nav styles are only to highlight the showing nav, they are not needed and can be restyled as wished
*/
nav {
background-color: pink;
border: 1px solid red;
}<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button type="button" class="hide-menu"> Hide Menu </button>
<nav>
<a href="#"> link </a>
</nav>
发布于 2020-04-08 06:47:31
也许你只需要
$('.hide-menu').click(function (event) {
event.preventDefault();
$('body').toggleClass('hide-sidebar');
});https://stackoverflow.com/questions/61094665
复制相似问题