Skip to content

Instantly share code, notes, and snippets.

@almazka987
Last active July 24, 2019 02:14
Show Gist options
  • Save almazka987/af7ff4cd63ae610bad044c48b4c05009 to your computer and use it in GitHub Desktop.
Save almazka987/af7ff4cd63ae610bad044c48b4c05009 to your computer and use it in GitHub Desktop.
JS code for open and close menu on click on burger button for mobile version of the menu, use with Tasty CSS-animated Hamburgers by Jonathan Suh

Hamburger mobile menu

Download 1 - hamburgers css library and 2 - animate.css library too - and include the CSS in the <head> of your site:

<link rel="stylesheet" href="animate.min.css">
<link href="dist/hamburgers.css" rel="stylesheet">

Or use hamburgers scss source files with your Sass CSS precompiler. Customize and compile it here.

in _base.scss:

.hamburger {
  display: none;
}

in responsive.scss:

/* max-width: 767px */
@media screen and (max-width: 767px) {
  .hamburger {
    display: inline-block;
  }
}

Add the base hamburger markup and append the class name of the type of hamburger you’re craving:

<button class="hamburger hamburger--squeeze" type="button">
  <span class="hamburger-box">
    <span class="hamburger-inner"></span>
  </span>
</button>  

in JS file:

// Mobile Menu
$('.hamburger').click(function() {
    $('#primary-navbar-collapse').stop().slideToggle().toggleClass('animated slideInTop');
    $(this).stop().toggleClass('is-active');
});

// Close mobile menu
$('.mobile #menu-primary li a, .tablet #menu-primary li a').on("click", function() {
    $('.hamburger').click();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment