Flat Horizontal Toggle Menu with jQuery and CSS3
| File Size: | 1.76 KB |
|---|---|
| Views Total: | 3929 |
| Last Update: | |
| Publish Date: | |
| Official Website: | Go to website |
| License: | MIT |
A modern flat designed horizontal navigation menu with an animated hamburger button, based on jQuery and CSS3 transitions & transforms.
How to use it:
1. Create a navigation menu with a toggle button following the markup structure like this:
<nav>
<div class="toggleNav">
<div class="toggleNavButton"></div>
</div>
<div id="subnav">
<ul>
<li> <a href="#">Menu Item 1</a> </li>
<li> <a href="#">Menu Item 2</a> </li>
<li> <a href="#">Menu Item 3</a> </li>
</ul>
</div>
</nav>
2. The global CSS styles.
* {
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
box-sizing: border-box;
text-decoration: none;
list-style: none;
padding: 0;
margin: 0;
}
body {
color: #F2F2F2;
background-color: #41558C;
}
3. The CSS/CSS3 rules to create smooth hamburger button transition effects.
.toggleNavButton {
transition-duration: 0.5s;
width: 40px;
height: 2px;
background-color: white;
position: absolute;
left: 50%;
top: 25px;
margin-left: -20px;
border-radius: 2px;
}
.toggleNavButton:before,
.toggleNavButton:after {
border-radius: 2px;
transition-duration: 0.5s;
content: "";
position: absolute;
top: 10px;
left: 0;
background-color: white;
width: 40px;
height: 2px;
}
.toggleNavButton:after { top: 20px; }
.toggleNavButton.active { width: 0; }
.toggleNavButton.active:after {
top: 10px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
.toggleNavButton.active:before {
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
}
.toggleNav {
border-bottom: 5px solid #15e1af;
background-color: #54EFC9;
width: 100%;
height: 80px;
text-align: center;
line-height: 80px;
cursor: pointer;
color: white;
font-size: 30px;
}
.toggleNav:hover { border-bottom: 5px solid #13ca9d; }
4. The required CSS to styles the navigation menu.
nav {
width: 100%;
min-height: 50px;
}
#subnav {
width: 100%;
border-bottom: 0px solid #e60b3e;
background-color: #F64870;
transition-duration: 0.2s;
overflow: hidden;
height: 0px;
}
#subnav.active {
border-bottom: 5px solid #e60b3e;
height: 50px;
}
#subnav ul {
width: 615px;
margin: 0 auto;
}
#subnav ul li {
transition-duration: 0.3s;
display: inline-block;
text-align: center;
width: 150px;
padding: 10px 0;
height: 50px;
}
#subnav ul li a { color: white; }
#subnav ul li:hover { background-color: #e60b3e; }
5. Include the necessary jQuery library at the bottom of the web page.
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
6. A little javascript to enable the toggle mnu.
$(".toggleNav").click(function () {
$("#subnav").toggleClass("active");
$(".toggleNavButton").toggleClass("active");
});
This awesome jQuery plugin is developed by Lewitje. For more Advanced Usages, please check the demo page or visit the official website.











