Skip to content

Instantly share code, notes, and snippets.

@rahuladams
Last active June 19, 2020 12:33
Show Gist options
  • Save rahuladams/07a0fd6199154060a7636d5e12f0f897 to your computer and use it in GitHub Desktop.
Save rahuladams/07a0fd6199154060a7636d5e12f0f897 to your computer and use it in GitHub Desktop.
//HTML
<div id="burger">
<button class="hamburger hamburger--elastic ripple" type="button">
<span class="hamburger-box">
<span class="hamburger-inner"></span>
</span>
</button>
</div>
//CSS
.hamburger {
display: inline-block;
overflow: visible;
padding: 15px;
transition-timing-function: linear;
transition-duration: .15s;
transition-property: opacity,filter;
border: 0;
float: right;
background-color: transparent;
outline: 0;
outline-style: none;
cursor: pointer;
}
.hamburger-box {
position: relative;
display: inline-block;
width: 35px;
height: 24px
}
.hamburger--elastic .hamburger-inner {
top: 2px;
transition-timing-function: ease;
transition-duration: .5s
}
.hamburger-inner,.hamburger-inner:after,.hamburger-inner:before {
position: absolute;
width: 100%;
height: 2px;
background-color: #000;
left: 0;
transition: all .5s cubic-bezier(.165,.84,.44,1);
}
.hamburger-inner:after,.hamburger-inner:before {
display: block;
content: "";
}
.hamburger--elastic .hamburger-inner:before {
top: 10px;
}
.hamburger--elastic .hamburger-inner:after {
top: 20px;
transition: all .5s ease
}
.hamburger-inner:after {
bottom: -10px
}
.hamburger--elastic.is-active .hamburger-inner {
transition-delay: 75ms;
transform: translate3d(0, 10px, 0) rotate(135deg)
}
.hamburger--elastic.is-active .hamburger-inner:before {
transition-delay: 0s;
opacity: 0
}
.hamburger--elastic.is-active .hamburger-inner:after {
transition-delay: 75ms;
transform: translate3d(0, -20px, 0) rotate(-270deg)
}
//Javascript
var menu_nav = document.querySelector("#burger");
if (menu_nav != null) {
menu_nav.addEventListener('click', function () {
global_menu.classList.add('active');
mybody.classList.add('menu_active');
});
close_menu.addEventListener('click', function () {
global_menu.classList.remove('active');
mybody.classList.remove('menu_active');
});
}
function checkKey(e) {
e = e || window.event;
if (e.keyCode == "27") {
$("#global_menu").removeClass("active");
$("body").removeClass("menu_active");
$("#burger button").removeClass('is-active');
$("#header").removeClass("showing_menu");
}
}
document.onkeydown = checkKey;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment