Skip to content

Instantly share code, notes, and snippets.

@manfromanotherland
Last active October 6, 2016 09:56
Show Gist options
  • Save manfromanotherland/86e6fbf69e8fb984eaf88de40bcc8ff9 to your computer and use it in GitHub Desktop.
Save manfromanotherland/86e6fbf69e8fb984eaf88de40bcc8ff9 to your computer and use it in GitHub Desktop.
JS: Simple solution to open navigation panel
/**
* Nav Toggle
* Inspired by John's Hamburgler http://johnm.io/project/hamburgler/
*/
(function() {
document.getElementById('js-nav').addEventListener('click', checkNav);
window.addEventListener("keyup", function(e) {
if (e.keyCode == 27) closeNav();
}, false);
function checkNav(event) {
event.preventDefault();
document.body.classList.contains('nav--open') ? closeNav() : openNav()
}
function closeNav() {
document.body.classList.remove('nav--open');
}
function openNav() {
document.body.classList.add('nav--open');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment