到目前为止,我成功地通过菜单图标打开和关闭菜单。但我想在任何点击时关闭它。我对如何解决这个问题感到不知所措。我尝试在 window/document/header/nav 上添加单击事件侦听器...但它似乎会在选择任何内容之前立即关闭菜单。你会如何处理这个问题?
let nav = document.querySelector(".header__nav");
function toggleNavOn() {
if (nav.style.visibility === "") {
nav.style.visibility = "visible";
} else {
nav.style.visibility = "";
}
navToggle.classList.toggle("header__nav_toggle--toggled")
}
let navToggle = document.querySelector(".header__nav_toggle");
navToggle.addEventListener("click", toggleNavOn);
<header class="header">
<div class="header__container">
<div class="header__container_logo">
<a class="header__logo_link" href="#"><img class="header__logo_img" src="img/vtol-logo.svg" alt="Vtol Logo"></a>
<a class="header__nav_toggle" href="javascript:void(0);">
<span></span>
</a>
</div>
<nav class="header__nav" id="nav-bar">
<a class="header__nav_link" href="#video-container">Watch</a>
<a class="header__nav_link" href="#features">Features</a>
<a class="header__nav_link" href="#about">About</a>
</nav>
</div>
</header>
叮当猫咪
忽然笑
宝慕林4294392
相关分类