title: Hamburger menu sliding
body: <p>I am trying to create a menu like the one on this website: <a href="http://sterling.it/en/" rel="nofollow noreferrer">http://sterling.it/en/</a></p>
  
  <p>I want my menu to slide from the left to the right and then to also disappear sliding to the left. Below is the code that I have written so far but it is not working properly. The menu slides the first time but then never slides again. I would really appreciate it if anyone could help me. Thanks in advance! </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function() {
    $(".menuTrigger").click(function() {
      $(this).toggleClass("active");
  
      /* Check if the icon does not have class active */
      if (!$(this).hasClass("active")) {
        /* Do something, for example add class color-icon that changes the color of the hamburguer,
          show an alert... */
        $(".menuTrigger .hamburger").addClass("non-active");
        $("#hamburgerMenu").removeClass("active");
  
      } else {
        $("menuTrigger .hamburger").removeClass("non-active");
        $("#hamburgerMenu").addClass("active");
        if ($(this).hasClass("active")) {
          $("#hamburgerMenu").animate({
            width: "200"
          });
        }
      }
    });
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body {
    background: pink;
  }
  
  .hamburger {
    width: 30px;
    height: 3px;
    background: black;
    position: absolute;
    top: 19px;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 2px 5px rgba(0, 0, 0, .2);
    transition: .5s;
  }
  
  .hamburger:before,
  .hamburger:after {
    content: "";
    position: absolute;
    width: 15px;
    height: 3px;
    background: black;
    box-shadow: 0 2px 5px rgba(0, 0, 0, .2);
    transition: .5s;
  }
  
  .hamburger:after {
    top: 8px;
    left: 50%;
  }
  
  .hamburger:before {
    top: -8px;
    left: 0%;
  }
  
  .menuTrigger:hover .hamburger:after {
    left: 0%;
  }
  
  .menuTrigger:hover .hamburger:before {
    left: 50%;
  }
  
  .menuTrigger.active .hamburger {
    background: rgba(0, 0, 0, 0);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0);
  }
  
  .menuTrigger.active .hamburger:before {
    top: 0px;
    -webkit-transform: rotate(-135deg);
    transform: rotate(-135deg);
    -webkit-transition: top .2s ease-in-out, -webkit-transform .3s ease-in-out .2s;
    transition: top .2s ease-in-out, -webkit-transform .3s ease-in-out .2s;
    transition: top .2s ease-in-out, transform .3s ease-in-out .2s;
    transition: top .2s ease-in-out, transform .3s ease-in-out .2s, - webkit-transform .3s ease-in-out .2s;
  }
  
  .menuTrigger.active .hamburger:after {
    top: 0px;
    background-color: rgba(0, 0, 0, 0);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0);
    -webkit-transition: top .2s ease-in-out, background-color .3s ease-in-out .2s;
    transition: top .2s ease-in-out, -webkit-transform .3s ease-in-out .2s;
    transition: top .2s ease-in-out, background-color .3s ease-in-out .2, box-shadow .3s ease-in-out .2s;
    transition: top .2s ease-in-out, background-color .3s ease-in-out .2s, -webkit-transform .3s ease-in-out .2s;
  }
  
  .menuTrigger.active .hamburger:after {
    top: 0px;
    -webkit-transform: rotate(-45deg);
    transform: rotate(-45deg);
    -webkit-transition: top .2s ease-in-out, -webkit-transform .3s ease-in-out .2s;
    transition: top .2s ease-in-out, -webkit-transform .3s ease-in-out .2s;
    transition: top .2s ease-in-out, transform .3s ease-in-out .2s;
    transition: top .2s ease-in-out, transform .3s ease-in-out .2s, - webkit-transform .3s ease-in-out .2s;
  }
  
  .menuTrigger {
    position: relative;
    transform: transition(-50%, -50%);
    width: 60px;
    height: 40px;
    align-items: center;
    z-index: 1000;
    cursor: pointer;
  }
  
  .hamburgerMenuTrigger {
    height: 100vh;
  }
  
  #hamburgerMenu {
    position: fixed;
    top: 0;
    height: 100%;
    width: 0px;
    padding: 60px;
    background-color: white;
    z-index: 1;
    visibility: hidden;
    opacity: 0;
  }
  
  #hamburgerMenu.active {
    opacity: 1;
    visibility: visible;
  }
  
  header nav a {
    text-decoration: none;
    color: rgb(88, 102, 110);
    font-size: 20px;
    font-weight: bold;
    padding: 7px;
  }
  
  header nav li {
    list-style-type: none;
    padding: 20px 0;
  }
  
  header nav li span {
    font-size: 16px;
    padding-right: 30px;
  }
  
  header {
    display: block;
  }
  
  header nav {
    padding-top: 80px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="hamburgerMenuTrigger"&gt;
    &lt;div class="menuTrigger" id="menuTriggerBtn"&gt;
      &lt;div class="hamburger" id="hamburgerBtn"&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div id="hamburgerMenu"&gt;
      &lt;nav class="hamburgereMenu-Nav"&gt;
        &lt;ul class="hamburgerMenu-Ul"&gt;
          &lt;li class="hamburgerMenu-nav-item  hamburgerMenu-right-li"&gt;&lt;a class="hamburgerMenu-nav-link  hamburgerMenu-menu" href=""&gt;&lt;span&gt;01&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li class="hamburgerMenu-nav-item hamburgerMenu-right-li"&gt;&lt;a class="hamburgerMenu-nav-link  hamburgerMenu-menu" href=""&gt;&lt;span&gt;02&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li class="hamburgerMenu-nav-item hamburgerMenu-right-li"&gt;&lt;a class="hamburgerMenu-nav-link  hamburgerMenu-menu" href=""&gt;&lt;span&gt;03&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li class="hamburgerMenu-nav-item  hamburgerMenu-right-li"&gt;&lt;a class="hamburgereMenu-nav-link  hamburgerMenu-menu" href=""&gt;&lt;span&gt;04&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/nav&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>