Skip to content

Instantly share code, notes, and snippets.

@hutch78
Created September 29, 2017 17:10
Show Gist options
  • Save hutch78/e508b125dfd57849d7e1b4ae6772227e to your computer and use it in GitHub Desktop.
Save hutch78/e508b125dfd57849d7e1b4ae6772227e to your computer and use it in GitHub Desktop.
A build-from-scratch hamburger menu. Needs to be cleaned up a bit
/*
Nav Toggle
Markup:
<button class="nav-toggle">
<span class="nav-toggle__icon">
<span class="nav-toggle__line top"></span>
<span class="nav-toggle__line middle"></span>
<span class="nav-toggle__line bottom"></span>
</span>
</button>
*/
$nticon-d: 55px;
$ntline-length: 30px;
$line-color: white;
.nav-toggle {
background-color: transparent;
border: none;
-webkit-appearance: none !important;
outline: none !important;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
// position: absolute;
@include ease-normal;
&.disabled {
pointer-events: none !important;
opacity: 0;
}
&:hover,
&:focus {
outline: none !important;
}
&__icon {
display: inline-block;
}
&__icon {
// border: 1px solid #e7e7e7;
width: $nticon-d;
height: $nticon-d;
position: relative;
@include ease-normal;
transform: scale(1);
overflow: hidden;
}
&__line {
height: 2px;
background-color: $line-color;
display: block;
position: absolute;
top: 50%;
right: 12.5px;
&.top {
width: $ntline-length;
-webkit-transform: translate3d(0,-7px,0);
transform: translate3d(0,-7px,0);
-webkit-transition: all 0.4s cubic-bezier(.17,.67,.35,1.41);
transition: all 0.4s cubic-bezier(.17,.67,.35,1.41);
}
&.middle {
width: $ntline-length;
-webkit-transform: translate3d(0,-50%,0);
transform: translate3d(0,-50%,0);
-webkit-transition: all .5s cubic-bezier(.17,.67,.35,1.41);
transition: all .5s cubic-bezier(.17,.67,.35,1.41);
}
&.bottom {
width: $ntline-length * .73;
-webkit-transform: translate3d(0,5px,0);
transform: translate3d(0,5px,0);
-webkit-transition: all .2s cubic-bezier(.17,.67,.35,1.41);
transition: all .2s cubic-bezier(.17,.67,.35,1.41);
}
}
&:not(.active){
@media #{$large-up}{
&:hover {
.nav-toggle__line {
&.top {
width: $ntline-length * .73;
}
&.middle {
width: $ntline-length * .5;
}
&.bottom {
width: $ntline-length;
}
}
}
}
}
&.active {
@media #{$large-up}{
&:hover {
.nav-toggle__line {
}
}
}
.nav-toggle__line {
&.top {
-webkit-transform: translate3d(0,-50%,0) rotate(-405deg);
transform: translate3d(0,-50%,0) rotate(-405deg);
}
&.middle {
-webkit-transform: translate3d(-200%,-50%,0);
transform: translate3d(-200%,-50%,0);
}
&.bottom {
width: $ntline-length;
-webkit-transform: translate3d(0,-50%,0) rotate(45deg);
transform: translate3d(0,-50%,0) rotate(45deg);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment