Skip to content

Instantly share code, notes, and snippets.

@devilshaircut
Created November 13, 2013 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devilshaircut/7458066 to your computer and use it in GitHub Desktop.
Save devilshaircut/7458066 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
$("#hamburger-icon").click(function() { // When the user clicks the #hamburger-icon HTML element ...
$("body").toggleClass("nav-expanded"); // ... toggle the <body> tag's ".nav-expanded" class on or off.
});
$("nav > ul > li > a").click(function() { // When the user clicks a navigation item in the hamburger menu ...
$("body").removeClass("nav-expanded"); // ... remove the ".nav-expanded" class (if it exists) from the <body> tag.
}); // This makes the menu a bit nicer to interact with for our users.
});
$(window).resize(function() { // When the window resizes ...
$("body").removeClass("nav-expanded"); // ... also remove the ".nav-expanded" class (if it exists) from the <body> tag.
}); // This takes care of the case where a user might resize the window for some reason.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment