Instantly share code, notes, and snippets.
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save Lysindr/c58139f731beaab9f9cdfebef8d7daab to your computer and use it in GitHub Desktop.
Mobile menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SCSS | |
//////Desktop | |
.navmenu { | |
width: 382px; | |
font-family: $lato-regular; | |
text-transform: uppercase; | |
color: #fff; | |
& > ul { | |
display: flex; | |
justify-content: space-between; | |
li { | |
a { | |
letter-spacing: 0.5px; | |
color: $heading-color; | |
transition: .3s all; | |
&:hover { | |
color: $main-color; | |
} | |
&.active { | |
position: relative; | |
color: $main-color; | |
&::before { | |
content: ""; | |
position: absolute; | |
left: 50%; | |
top: 28px; | |
border: 4px solid transparent; | |
border-bottom: 5px solid $main-color; | |
transform: translateX(-50%); | |
} | |
} | |
} | |
} | |
} | |
} | |
//Mobile | |
@media (min-width: 320px) and (max-width: 991px) { | |
//Mobile ver.2 | |
.overlay { | |
position: absolute; | |
right: 0; | |
top: 66px; | |
z-index: 5; | |
width: auto; | |
} | |
.navmenu { | |
overflow: hidden; | |
width: 255px; | |
max-height: 0; | |
transition-duration: 1s; | |
& > ul { | |
flex-direction: column; | |
padding: 15px 0; | |
background-color: #e6e6e6; | |
li { | |
display: block; | |
margin-right: 0; | |
text-align: center; | |
& + li { | |
margin-top: 15px; | |
} | |
a { | |
&:hover { | |
border-bottom: none; | |
} | |
&.active { | |
&::before { | |
top: 12px; | |
} | |
} | |
} | |
} | |
} | |
&.opened { | |
visibility: visible; | |
opacity: 1; | |
max-height: 130px; | |
background-color: #e6e6e6; | |
} | |
} | |
#menu-button { | |
position: relative; | |
right: 0; | |
display: block; | |
width: 40px; | |
height: 40px; | |
transform: rotate(0deg); | |
transition-duration: .5s; | |
transition-timing-function: ease-in-out; | |
cursor: pointer; | |
&.open { | |
span { | |
&:nth-child(1) { | |
top: 18px; | |
left: 50%; | |
width: 0%; | |
} | |
&:nth-child(2) { | |
top: 16px; | |
transform: rotate(45deg); | |
} | |
&:nth-child(3) { | |
bottom: 18px; | |
transform: rotate(-45deg); | |
} | |
} | |
} | |
span { | |
position: absolute; | |
left: 0; | |
display: block; | |
width: 100%; | |
height: 6px; | |
border-radius: 9px; | |
background: $main-color; | |
transform: rotate(0deg); | |
transition-duration: .25s; | |
transition-timing-function: ease-in-out; | |
&:nth-child(1) { | |
top: 2px; | |
} | |
&:nth-child(2) { | |
top: 17px; | |
} | |
&:nth-child(3) { | |
bottom: 2px; | |
} | |
} | |
} | |
} | |
//Mob ver.2 END | |
@media (max-width: 480px) { | |
.menu { | |
top: 0; | |
} | |
} | |
/* | |
<div class="logo"><a href="#"><span>M</span>edical <span>+</span> </a></div> | |
<a href="#" class="header-button registration"></a> | |
<a href="#" class="header-button login"></a> | |
<div id="menu-button"> | |
<span></span> | |
<span></span> | |
<span></span> | |
</div> | |
<div class="overlay"> | |
<nav class="navmenu"> | |
<ul> | |
<li><a href="#" class="active">Home</a></li> | |
<li><a href="#">Services</a></li> | |
<li><a href="#">About</a></li> | |
<li><a href="#">Blog</a></li> | |
<li><a href="#">Pages</a></li> | |
</ul> | |
</nav> | |
</div> | |
*/ | |
JS | |
//// | |
//Mob menu ver2 | |
var touch = $('#menu-button'); | |
var menu = $('.navmenu'); | |
var overlay = $('.overlay'); | |
$(touch).on('click', function(e) { | |
e.preventDefault(); | |
menu.toggleClass('opened'); | |
overlay.toggleClass('opened'); | |
}); | |
$('#menu-button').click(function() { | |
$(this).toggleClass('open'); | |
}); | |
$(document).click(function(event) { | |
if ($(event.target).closest(touch).get(0) == null) { | |
menu.removeClass('opened'); | |
if (touch.hasClass('open')) { | |
touch.toggleClass('open'); | |
} | |
} | |
}); | |
//Mob menu ver2 end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment