滚动时我的汉堡包图标消失

时间:2018-07-15 03:48:10

标签: javascript html mobile scroll menu

我不知道为什么滚动页面时菜单图标会消失。 这是我的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&notif_id=1530027180752658&notif_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>

0 个答案:

没有答案