Created
August 5, 2015 21:20
-
-
Save taniarascia/89d29f351fcc0aa0d62b to your computer and use it in GitHub Desktop.
Enable Dropdown Navigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; | |
(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