Show and hide toggle menu. Show function does not work. Can you help me?

Asked

Viewed 102 times

0

<!-- header -->
			<header class="header header-fixheight header--fixed">
				<div class="container">
					<div class="header__inner">
						<div class="header-logo"><a href="home.html"><img src="assets/img/logo-menu.png" alt=""/></a></div>
						
						<!-- raising-nav -->
						<nav class="raising-nav">
							
							<!-- raising-menu -->
							<ul class="raising-menu" id="menu-1">
								<li class="current"><a class="nav-link" href="#id1">Home</a>
								</li>
								<li><a class="nav-link" href="#id2">Sobre Nós</a>
								</li>
								<li><a class="nav-link" href="#id3">Serviços</a>
								</li>
								<li><a class="nav-link" href="#id4">Galeria</a>
								</li>
								<li><a class="nav-link" href="#id5">Depoimentos</a>
								</li>
								<li><a class="nav-link" href="#id6">Sobre</a>
								</li>
								<li><a class="nav-link" href="#id7">Contato</a>
								</li>
							</ul><!-- raising-menu -->
							
							<div class="navbar-toggle" id="hamburguer"><i class="fa fa-bars" onclick="mostrarmenu()"></i></div>

						</nav><!-- Fim / raising-nav -->
					</div>
				</div>
			</header><!-- Fim / header -->

In the code below, the function hides well, but does not work to show. Can you help me solve?

<script type="text/javascript">
        	$(document).ready(function(){
    			$(".nav-link").click(function(){
      				$("#menu-1").toggle('hide');
    			});
  			});

  			function mostrarmenu(){
      			$("#menu-1").toggle('show');	
        	}
</script>

  • 1

    Edit your question and put the html will make it easy to answer you

1 answer

1

I think you must have made some kind of mistake, the jQuery method toggle() toggles the visibility of the elements by itself, no need to pass parameters of Hide or show:

$("#menu-1").hide();

$(document).ready(function() {
  $(".nav-link").click(function() {
    $("#menu-1").toggle();
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<button class="nav-link">Mostrar/Esconder</button>

<ul id="menu-1">
  <li>1</li>
  <li>2</li>
  <li>3</li>
</ul>

  • As I said, Only closes with the above code, but after it closes it does not open again. The menu starts to appear and hides again

  • With the code you posted, what did you expect to happen? The only result is what you said yourself, when you click on the links you hide them, how would you get them open again?

Browser other questions tagged

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