Responsive menu does not close when selecting element

2

I made a responsive menu on a one page site.

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

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>

    
asked by anonymous 21.05.2015 / 16:09

1 answer

1

Make a schedule with the click event on top of the clicked element 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 change to the id of this button ex: $('#idBotao').click();     

21.05.2015 / 16:11