Instantly share code, notes, and snippets.
Created
January 28, 2019 20:46
-
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 ncesar/1c82e70acd0169203389503898da5e05 to your computer and use it in GitHub Desktop.
hamburgermenu using jquery and css. made by salah uddin
This file contains hidden or 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
/* html */ | |
<button id="hamburger-menu" data-toggle="ham-navigation" class="hamburger-menu-button"><span class="hamburger-menu-button-open">Menu</span></button> | |
<nav id="ham-navigation" class="ham-menu"> | |
<ul class="menu"> | |
<li><a href="#">Home</a></li> | |
<li class="active"><a href="#">About</a></li> | |
<li><a href="#">Services</a></li> | |
<li><a href="#">Features</a></li> | |
<li><a href="#">Products</a></li> | |
<li><a href="#">Contact</a></li> | |
</ul> | |
</nav> | |
/* css */ | |
@import url(https://fonts.googleapis.com/css?family=Roboto:300,400,500,700); | |
body { | |
font-family: 'Roboto', sans-serif; | |
color: #444444; | |
} | |
a { | |
color: #ff7013; | |
text-decoration: none; | |
} | |
.hamburger-menu-button { | |
width: 40px; | |
height: 40px; | |
padding: 6px; | |
display: block; | |
position: relative; | |
margin-top: 35px; | |
z-index: 100; | |
background: #2980b9; | |
border: 5px solid white; | |
box-sizing: content-box; | |
border-radius: 50%; | |
text-indent: 100%; | |
color: transparent; | |
white-space: nowrap; | |
cursor: pointer; | |
overflow: hidden; | |
} | |
.hamburger-menu-button-open { | |
top: 50%; | |
margin-top: -1px; | |
left: 50%; | |
margin-left: -12px; | |
} | |
.hamburger-menu-button-open, | |
.hamburger-menu-button-open::before, | |
.hamburger-menu-button-open::after { | |
position: absolute; | |
width: 24px; | |
height: 2px; | |
background: #fff; | |
border-radius: 4px; | |
-webkit-transition: all 0.3s; | |
transition: all 0.3s; | |
} | |
.hamburger-menu-button-open::before, | |
.hamburger-menu-button-open::after { | |
left: 0; | |
content: ""; | |
} | |
.hamburger-menu-button-open::before { | |
top: 6px; | |
} | |
.hamburger-menu-button-open::after { | |
bottom: 6px; | |
} | |
.hamburger-menu-button-close { | |
background: transparent; | |
-webkit-transform: rotate(180deg); | |
transform: rotate(180deg); | |
} | |
.hamburger-menu-button-close::before { | |
-webkit-transform: translateY(-6px) rotate(45deg); | |
transform: translateY(-6px) rotate(45deg); | |
} | |
.hamburger-menu-button-close::after { | |
-webkit-transform: translateY(6px) rotate(-45deg); | |
transform: translateY(6px) rotate(-45deg); | |
} | |
.ham-menu { | |
position: absolute; | |
top: 42px; | |
left: 48px; | |
margin: auto; | |
max-width: 570px; | |
overflow: hidden; | |
} | |
.ham-menu ul { | |
-webkit-transform: translateX(-110%); | |
transform: translateX(-110%); | |
background-color: #3896d3; | |
-webkit-transition: all 0.5s ease-in-out; | |
transition: all 0.5s ease-in-out; | |
} | |
.ham-menu.on ul { | |
-webkit-transform: translateX(0px); | |
transform: translateX(0px); | |
} | |
.ham-menu ul { | |
font-size: 0; | |
} | |
.ham-menu ul li { | |
display: inline-block; | |
} | |
.ham-menu ul li:first-child .ham-menu ul li a { | |
padding-left: 30px; | |
} | |
.ham-menu ul li a { | |
padding: 15px; | |
display: block; | |
background-color: transparent; | |
color: #fff; | |
text-transform: uppercase; | |
-webkit-transition: all 0.2s ease-in-out; | |
transition: all 0.2s ease-in-out; | |
font-size: 13px; | |
} | |
.ham-menu ul li.active a, .ham-menu ul li a:hover { | |
background-color: #2980b9; | |
color: #fff !important; | |
} | |
/* js */ | |
var button = document.getElementById('hamburger-menu'), | |
span = button.getElementsByTagName('span')[0]; | |
button.onclick = function() { | |
span.classList.toggle('hamburger-menu-button-close'); | |
}; | |
$('#hamburger-menu').on('click', toggleOnClass); | |
function toggleOnClass(event) { | |
var toggleElementId = '#' + $(this).data('toggle'), | |
element = $(toggleElementId); | |
element.toggleClass('on'); | |
} | |
// close hamburger menu after click a | |
$( '.menu li a' ).on("click", function(){ | |
$('#hamburger-menu').click(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment