我不知道为什么滚动页面时菜单图标会消失。 这是我的HTML代码:
<nav id="navbar" class="navbar navbar-expand-md navbar-dark fixed-top bg-dark" data-spy="affix" data-offset-top="197">
<h2 style="display:none;">Navegación KSLM</h2>
<a class="klsm" href="#">KSLM</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item active" data-toggle="collapse" data-target=".navbar-collapse.in">
<a class="nav-link" href="#inicio">INICIO</a>
</li>
<li class="nav-item" data-toggle="collapse" data-target=".navbar-collapse.in">
<a class="nav-link" href="#acercade">ACERCA DE</a>
</li>
<li class="nav-item" data-toggle="collapse" data-target=".navbar-collapse.in">
<a class="nav-link" href="#servicios">SERVICIOS</a>
</li>
<li class="nav-item" data-toggle="collapse" data-target=".navbar-collapse.in">
<a class="nav-link" href="#ubicacion">UBICACIÓN</a>
</li>
<li class="nav-item" data-toggle="collapse" data-target=".navbar-collapse.in">
<a class="nav-link" href="#contacto">CONTACTO</a>
</li>
<li class="nav-item" data-toggle="collapse" data-target=".navbar-collapse.in">
<a class="nav-link" href="https://www.facebook.com/kslmconsultores/?notify_field=blurb&modal=profile_completion¬if_id=1530027180752658¬if_t=page_profile_blurb "></a>
</li>
</ul>
</div>
</nav>
这是我的JS:
<script>window.onscroll = () => {
const nav = document.querySelector('#navbar');
nav.className = (this.scrollY <= 500) ? '' : 'scroll';
}; </script>