Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<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.

>Solution :

After the click, your 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') })
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading