Skip to content

Instantly share code, notes, and snippets.

@privard
Created March 17, 2014 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save privard/9598745 to your computer and use it in GitHub Desktop.
Save privard/9598745 to your computer and use it in GitHub Desktop.
Hamburger Cross
<section>
<nav>
<a class="navicon-button x">
<div class="navicon"></div>
</a>
</nav>
</section>
$(".navicon-button").click(function(){
$(this).toggleClass("closed");
});
@hamburgerWidth: 5em;
@hamburgerHeight: 0.125 * @hamburgerWidth;
@hamburgerMargin: (@hamburgerWidth / sqrt(2) - 3*@hamburgerHeight)/2;
@translateX: 0.19047619*@hamburgerWidth;
@translateY: 0.285714286*@hamburgerWidth;
@transition: 0.3s;
.line {
width: @hamburgerWidth;
height: @hamburgerHeight;
border-radius: 1.5em;
background-color: #c6c6c6;
position: relative;
}
.navicon-button {
display: inline-block;
padding: 1em;
cursor: pointer;
-webkit-transition: all @transition;
&:before, &:after {
content: '';
display: block;
.line;
-webkit-transition: all @transition;
-webkit-backface-visibility: hidden;
}
&:before {margin-bottom: @hamburgerMargin;}
&:after {margin-top: @hamburgerMargin;}
&.closed{
.navicon{
opacity: 0;
-webkit-transition: all @transition;
}
&:after{
-webkit-transform: translate(-1*@translateX, -1*@translateY) rotate(-45deg);
-webkit-transition: all @transition;
}
&:before{
-webkit-transform: translate(-1*@translateX, @translateY) rotate(45deg);
-webkit-transition: all @transition;
}
}
}
.navicon {
.line;
}
* { box-sizing: border-box; }
html{ background-color: #333; font-size: 14px; }
section { background-color: #000; }
@privard
Copy link
Author

privard commented Mar 17, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment