Skip to content

Instantly share code, notes, and snippets.

@frankyonnetti
Last active May 23, 2021 19:56
Show Gist options
  • Select an option

  • Save frankyonnetti/f18aba0ed8ddbbbfee5cb32e754d6125 to your computer and use it in GitHub Desktop.

Select an option

Save frankyonnetti/f18aba0ed8ddbbbfee5cb32e754d6125 to your computer and use it in GitHub Desktop.
Mobile menu icon #mobile #menu
<div id="mobile-menu-icon">
<i></i>
<i></i>
<i></i>
<i></i>
<span>menu</span>
</div>
// ! mobile menu
const mobileMenuContainer = '.site-header'
const mobileMenu = $('.site-header #site-navigation')
const mobileMenuIcon = '.site-header #mobile-menu-icon'
const animateTime = 200
function autoHeightAnimate (element, time) {
const curHeight = element.height() // Get Default Height
const autoHeight = element.css('height', 'auto').height() // Get Auto Height
element.height(curHeight) // Reset to Default Height
element.stop().animate({ height: autoHeight }, time) // Animate to Auto Height
}
// toggle class
$(mobileMenuIcon).click(function () {
if ($(mobileMenuContainer).hasClass('mobile-menu-open')) {
$(mobileMenuContainer).removeClass('mobile-menu-open')
mobileMenu.stop().animate({ height: '0' }, animateTime)
} else {
$(mobileMenuContainer).addClass('mobile-menu-open')
autoHeightAnimate(mobileMenu, animateTime)
}
})
// activate on viewport width. requires viewportCore
$(window).resize(viewportCore.waitForIdle(function () {
if (viewportCore.viewportWidth > 768) {
// Clear out mobile-menu.
$(mobileMenuContainer).removeClass('mobile-menu-open')
mobileMenu.css('height', '')
}
}, 200))
// ! mobile menu
header {
nav {
@media (max-width: 768px) {
overflow: hidden;
padding: 0 !important;
height: 0;
}
}
&.mobile-menu-open {
#mobile-menu-icon {
i:nth-child(1) {
top: 6px;
left: 50%;
width: 0;
}
i:nth-child(2) {
transform: rotate(45deg);
}
i:nth-child(3) {
transform: rotate(-45deg);
}
i:nth-child(4) {
top: 6px;
left: 50%;
width: 0;
}
}
}
#mobile-menu-icon {
border-width: 17px 15px;
border-style: solid;
border-color: rgba($white, 0);
border-radius: 3px 0 0 3px;
position: absolute;
top: 14px;
right: 0;
width: 56px;
height: 49px;
cursor: pointer;
@media #{$breakpoint-md-up} {
top: -99999px;
}
span {
color: $white;
position: absolute;
top: -3px;
right: 32px;
}
i {
transform: rotate(0deg);
transition: all 0.25s cubic-bezier(0.55, 0, 0.1, 1);
border-radius: 7px;
background-color: $white;
display: block;
position: absolute;
left: 0;
width: 100%;
height: 3px;
}
i:nth-child(1) {
top: 0;
}
i:nth-child(2),
i:nth-child(3) {
top: 6px;
}
i:nth-child(4) {
top: 12px;
}
}
#mobile-menu-icon:hover {
-webkit-tap-highlight-color: transparent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment