A Pen by Joseph Turner on CodePen.
Created
March 10, 2015 20:53
-
-
Save joseph-turner/bb170c90ea81e3fff216 to your computer and use it in GitHub Desktop.
Hamburger Animations
This file contains hidden or 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
a#hamburger.hamburger(href="#") | |
i.top | |
i.middle | |
i.bottom |
This file contains hidden or 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($) { | |
$('#hamburger').on('click', function(e) { | |
e.preventDefault(); | |
$(this).toggleClass('is-open'); | |
}); | |
})(jQuery); |
This file contains hidden or 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
body { | |
padding: 40px; | |
} | |
*,*:before,*:after { | |
box-sizing: border-box; | |
} | |
// Variables | |
$line-weight: 6px; | |
$line-color: gray; | |
$hamburger-width: 45px; | |
.hamburger { | |
position: relative; | |
display: inline-block; | |
width: 45px; | |
height: 35px; | |
i { | |
position: absolute; | |
left: calc(50% - #{$hamburger-width / 2}); | |
width: $hamburger-width; | |
height: $line-weight; | |
background: $line-color; | |
border-radius: $line-weight; | |
transition: .3s ease-in-out; | |
&.top, | |
&.bottom { | |
transition: all .3s ease-in-out .3s, transform .3s ease-in-out; | |
} | |
&.top { | |
top: 0; | |
} | |
&.middle { | |
top: calc(50% - #{$line-weight / 2}); | |
} | |
&.bottom { | |
top: calc(100% - #{$line-weight}); | |
} | |
} | |
&.is-open { | |
i { | |
&.top { | |
top: calc(50% - #{$line-weight / 2}); | |
transition: all .3s ease-in-out, transform .3s ease-in-out .3s; | |
transform: rotate(135deg); | |
} | |
&.middle { | |
transform: rotate(-315deg); | |
} | |
&.bottom { | |
top: calc(50% - #{$line-weight / 2}); | |
transform: rotate(135deg); | |
transition: all .3s ease-in-out, transform .3s ease-in-out .3s; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment