Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
Why button function only works once

i have sidebar if i click on button and then side bar appears from left, and when i click on body side bar hides, but why it is happening only for once.

FIDDLE

HTML

<body>
  <div class="site-overlay"></div>
  <a href="#menu" class="menu-link"> button &#9776;</a>
  <nav id="menu" class="panel" role="navigation">
      <ul>
          <li><a href="#">Home</a></li>
          <li><a href="#">The Ballad of El Goodo</a></li>
          <li><a href="#">Thirteen</a></li>
          <li><a href="#">September Gurls</a></li>
          <li><a href="#">What's Going Ahn</a></li>
      </ul>
  </nav>
</body>

JS:

$(document).ready(function() {
  $('.menu-link').bigSlide({
    easyClose: true
  });
  $('.menu-link').click(function() {
        $('body').addClass('menu-open');
    });
});

CSS:

a.menu-link {
  float: right;
  padding: 20px
}

nav#menu {
  background: lightblue;
  z-index: 100000000000000
}

.site-overlay {
    display: none;
}
.menu-open .site-overlay {
    display: block;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 9998;
  
    -webkit-animation: fade 500ms;
    animation: fade 500ms;
}

HOW CAN I MAKE IT WORK IT MANY TIMES, instead of only one time.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

After the click, you're showing your overlay, but because it has z-index: 9998, the overlay is being placed on top of the button, so when you try to click the button, you're actually clicking on the overlay, not on the button.

You should make an event when the overlay is clicked to remove that class, like this:

$('.site-overlay').click(function() { $('body').removeClass('menu-open') })
about 4 years ago · Juan Pablo Isaza Relatório

0

This is because the added class is not removed.

You can control it by adding a toggle value for that button.

about 4 years ago · Juan Pablo Isaza Relatório

0

Instead of addClass put toggle.

On the way you put you will add "menu-open" once and it will never be removed.

you have more information about this here: https://www.w3schools.com/howto/howto_js_toggle_class.asp

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda