Skip to content

Instantly share code, notes, and snippets.

@Joeltbond
Created June 13, 2016 05:18
Show Gist options
  • Save Joeltbond/71b94a7bef30d6d248114724cc9bd486 to your computer and use it in GitHub Desktop.
Save Joeltbond/71b94a7bef30d6d248114724cc9bd486 to your computer and use it in GitHub Desktop.
simple font-awesome hamburger menu
.hidden {
display: none;
}
<a href="javascript:void(0);" id="menuButton" class="pull-right">
<i class="fa fa-bars pull-right"></i>
</a>
<nav id="menu" class="hidden text-center">
<ul>
<li><a href="about.html">About</a></li>
<li><a href="shop.html">Shop</a></li>
<li><a href="index.html">Portfolio</a></li>
</ul>
</nav>
(function () {
var menuButton = document.getElementById('menuButton');
var menuIcon = menuButton.children[0];
var menu = document.getElementById('menu');
var menuOpen = false;
function onMenuClick(event) {
if (menuOpen) {
menu.classList.add('hidden');
menuIcon.classList.remove('fa-times');
menuIcon.classList.add('fa-bars');
} else {
menu.classList.remove('hidden');
menuIcon.classList.add('fa-times');
menuIcon.classList.remove('fa-bars');
}
menuOpen = !menuOpen;
event.preventDefault();
}
menuButton.addEventListener('click', onMenuClick);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment