Responsive menu does not close when selecting element

Asked

Viewed 1,511 times

2

I made a responsive menu on a one page website.

The scrolling part of the page is working normally, but the menu only closes if the user clicks again on the menu icon.

I need the menu to close when the user selects one of the Nav elements.

 $('.efeito-desliza').click(function () {
            $('html, body').animate({
                scrollTop: $($(this).attr('href')).offset().top
            }, 1000);
            return false;
 });
 <nav class="navbar navbar-default">
   <div class="container">
     <div class="navbar-header">
       <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
         <span class="sr-only">Navegação Responsiva</span>

       </button>
       <a href="#home" class="img-responsive efeito-desliza navbar-brand"><img class="img-responsive"
                                                                               src="img/logo.png"></a>
     </div>
     <div id="navbarCollapse" class="menu-scroll collapse navbar-collapse menu">
       <ul class="nav navbar-nav ">
         <li><a class="efeito-desliza" href="#bu">SOLUÇÕES</a></li>
         <li><a class="efeito-desliza" href="#div-quemsomos">QUEM SOMOS</a></li>
         <li><a class="efeito-desliza" href="#depoimentos">DEPOIMENTOS</a></li>
         <li><a class="efeito-desliza" href="#contato">CONTATO</a></li>
       </ul>
     </div>
   </div>
    </nav>

inserir a descrição da imagem aqui

1 answer

1


Make a schedule with the click event on the element clicked to close the menu. Example:

$('.efeito-desliza').click(function () {
            $('html, body').animate({
                scrollTop: $($(this).attr('href')).offset().top
            }, 1000);
            $('.navbar-toggle').click(); // FAZ UM CLIQUE NO BOTAO QUE CHAMA O MENU PARA OCULTAR O MENU
            return false;

 });

Note: if it is not . navbar-toggle the button that clicks and opens the menu, then switch to the id of this button ex: $('#idBotao').click();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.