Skip to content

Instantly share code, notes, and snippets.

@powerbuoy
Created October 4, 2017 08:33
Show Gist options
  • Save powerbuoy/cf74de7b32c59b05fcbce9be866baeed to your computer and use it in GitHub Desktop.
Save powerbuoy/cf74de7b32c59b05fcbce9be866baeed to your computer and use it in GitHub Desktop.
Single element animated burger menu
$transition-default: .25s;
$transition-easing: ease-in-out;
@mixin burger-menu ($color: $color-link, $size: 1.5rem, $thickness: .25rem) {
background-image: linear-gradient(to right, transparent, transparent 25%, $color 25%);
// background-image: linear-gradient(to right, $color, $color); // Full width middle line
background-size: 100% $thickness;
background-position: left 50%;
background-repeat: no-repeat;
transition: background-position $transition-default $transition-default $transition-easing;
display: block;
position: relative;
overflow: hidden;
width: $size;
height: $size;
&::before,
&::after {
background: $color;
display: block;
content: "";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: $thickness;
transition: top $transition-default $transition-default $transition-easing, transform $transition-default $transition-easing;
}
&::after {
top: auto;
bottom: 0;
transition: bottom $transition-default $transition-default $transition-easing, transform $transition-default $transition-easing;
}
}
@mixin burger-menu-open ($color: $color-link, $size: 1.5rem, $thickness: .25rem) {
background-position: $size 50%;
transition: background-position $transition-default $transition-easing;
&::before {
top: calc(50% - #{$thickness / 2});
transform: rotate(45deg);
transition: top $transition-default $transition-easing, transform $transition-default $transition-default $transition-easing;
}
&::after {
bottom: calc(50% - #{$thickness / 2});
transform: rotate(-45deg);
transition: bottom $transition-default $transition-easing, transform $transition-default $transition-default $transition-easing;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment