Last active
August 29, 2015 14:14
-
-
Save verticalgrain/c8973cc5b29561c3c988 to your computer and use it in GitHub Desktop.
Animated hamburger menu trigger - animates from a hamburger to an "X" - SCSS, HTML, JS, Compass
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
<div class="nav-trigger"> | |
<span></span> | |
<span></span> | |
<span></span> | |
</div> |
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
$('.nav-trigger').on('click', function() { | |
$('body').toggleClass('nav-active'); | |
}); |
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
// Animated hamburger icon for mobile navigation | |
.nav-trigger { | |
display: none; | |
position: absolute; | |
right: 20px; | |
top: 20px; | |
width: 20px; | |
height: 16px; | |
z-index: 99; | |
&:hover { | |
cursor: pointer; | |
} | |
@media (max-width: 960px) { | |
display: block; | |
} | |
span { | |
width: 20px; | |
height: 2px; | |
position: absolute; | |
@include transform-origin(0); | |
background: black; | |
@include transition-duration(0.3s); | |
&:nth-of-type(1) { | |
top: 0; | |
left: 0px; | |
} | |
&:nth-of-type(2) { | |
top: 7px; | |
@include opacity(1); | |
} | |
&:last-of-type { | |
bottom: 0; | |
left: 0; | |
} | |
} | |
.nav-active & { | |
span { | |
background: white; | |
&:nth-of-type(1) { | |
@include rotate(45deg); | |
} | |
&:nth-of-type(2) { | |
@include opacity(0); | |
} | |
&:last-of-type { | |
@include rotate(-45deg); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment