Skip to content

Instantly share code, notes, and snippets.

@artbah
Created July 27, 2018 03:35
Show Gist options
  • Save artbah/076350fb17d28ffcd144f35d77ac5830 to your computer and use it in GitHub Desktop.
Save artbah/076350fb17d28ffcd144f35d77ac5830 to your computer and use it in GitHub Desktop.
Animated - Hamburger Icon (spans)
<div class="container">
<a href="#" class="menu-button [ js-menu-button ]">
<div class="menu-icon">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</a>
</div>
function updateMenuButton() {
$('.js-menu-button').find('.menu-icon').toggleClass('is-active');
}
$(document).ready(function() {
$('.js-menu-button').click(function(e){
e.preventDefault();
updateMenuButton();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
.container {
display: flex;
align-items: center;
justify-content: center;
background-color: #ededed;
min-height: 100vh;
}
/////
//
// Menu Icon
//
/////
$menu-icon-width: 3em;
$menu-icon-height: $menu-icon-width * 0.75;
$menu-icon-color: #363636;
$menu-icon-color--active: #D00251;
.menu-icon {
position: relative;
width: $menu-icon-width;
height: $menu-icon-height;
display: inline-block;
}
.menu-icon span {
position: absolute;
height: $menu-icon-width / 16;
width: 100%;
background-color: $menu-icon-color;
transition: all 250ms ease-in-out;
transform: rotate(0deg);
box-shadow: 0px 1px 1px rgba(255,255,255,0.6);
}
.menu-icon span:nth-child(1) {
top: $menu-icon-width / 32;
}
.menu-icon span:nth-child(2),
.menu-icon span:nth-child(3) {
top: $menu-icon-width / 3.2;
}
.menu-icon span:nth-child(4) {
top: $menu-icon-width * 0.625;
}
.menu-button:hover span,
.menu-button:focus span,
.menu-button:active span {
background: $menu-icon-color--active;
}
.menu-icon.is-active span:nth-child(1),
.menu-icon.is-active span:nth-child(4) {
opacity: 0;
}
.menu-icon.is-active span:nth-child(2) {
transform: rotate(45deg);
}
.menu-icon.is-active span:nth-child(3) {
top: $menu-icon-width / 3.2;
transform: rotate(-45deg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment