Skip to content

Instantly share code, notes, and snippets.

@taniarascia
Created August 5, 2015 21:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taniarascia/89d29f351fcc0aa0d62b to your computer and use it in GitHub Desktop.
Save taniarascia/89d29f351fcc0aa0d62b to your computer and use it in GitHub Desktop.
Enable Dropdown Navigation
;
(function ($) {
// DOM ready
$(function () {
// Toggle open and close nav styles on click
$('#nav-toggle').click(function () {
$('.nav-list').toggle();
});
// Toggle active CSS class (X - close)
document.querySelector("#nav-toggle").addEventListener("click", function () {
this.classList.toggle("active");
});
// If a link has a dropdown, add sub menu toggle.
$('nav ul li > a:not(:only-child)').click(function (e) {
$(this).siblings('.nav-dropdown').toggle();
// Close one dropdown when selecting another
$('.nav-dropdown').not($(this).siblings()).hide();
e.stopPropagation();
});
// Clicking away from dropdown will remove the dropdown class
$('html').click(function(){
$('.nav-dropdown').hide();
});
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment