Left-to-right Push Menu With jQuery And CSS3

Left-to-right Push Menu With jQuery And CSS3
File Size: 4.01 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

Yet another mobile-friendly navigation system that allows your users to toggle a vertical off-screen navigation menu while push the main content from left to right.

How to use it:

1. Add the CSS class 'pushmenu-push' to the body tag.

<body class="pushmenu-push">

2. Create the off-screen menu from a nav list like this:

<nav class="pushmenu pushmenu-left">
  <ul class="links">
    <li> <a href="#">Home</a> </li>
    <li> <a href="#">About</a> </li>
    <li> <a href="#">Projects</a> </li>
    <li> <a href="#">Blog</a> </li>
    <li> <a href="#">Contacts</a> </li>
  </ul>
</nav>

3. Create a trigger element to toggle the navigation menu.

<div id="nav_list">MENU</div>

4. Style the navigation menu.

.pushmenu {
  background: #444;
  text-align: center;
  font-family: Tahoma, Geneva, sans-serif;
  width: 300px;
  height: 100%;
  top: 0;
  z-index: 1000;
  position: fixed;
}

.pushmenu h3 {
  color: #f1f1f1;
  font-size: 1.3em;
  font-weight: 400;
  padding: 15px 25px;
  margin: 0;
  background: #333;
  height: 16px;
}

.links {
  list-style-type: none;
  padding: 0;
  margin: 0 0 0 25%;
  width: 50%;
}

.links li { margin-top: 30px; }

.links li a {
  position: relative;
  display: block;
  color: #f1f1f1;
  font-size: 1.3em;
  font-weight: 400;
  text-decoration: none;
  padding: 14px;
}

.links li a:after {
  content: '';
  display: block;
  position: absolute;
  left: 20px;
  bottom: -5px;
  width: 0;
  height: 4px;
  background-color: #f1f1f1;
  -webkit-transition: width 0.3s ease;
  -moz-transition: width 0.3s ease;
  transition: width 0.3s ease;
}

.links li a:hover:after { width: 70%; }

.links li a:active { color: #dbdbdb; }

.pushmenu-left { left: -300px; }

.pushmenu-left.pushmenu-open { left: 0; }

.pushmenu-push {
  overflow-x: hidden;
  position: relative;
  left: 0;
}

.pushmenu-push-toright { left: 300px; }

5. Add a smooth transition effect to the navigation menu when opening / closing.

.pushmenu, .pushmenu-push {
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.5s ease;
  transition: all 0.5s ease;
}

6. Load the necessary jQuery library in the html page when needed.

<script src="//code.jquery.com/jquery.min.js"></script>

7. The JavaScript to toggle CSS classes when the navigation menu opens or closes.

$(document).ready(function() {
  $menuLeft = $('.pushmenu-left');
  $nav_list = $('#nav_list');
  
  $nav_list.click(function() {
    $(this).toggleClass('active');
    $('.pushmenu-push').toggleClass('pushmenu-push-toright');
    $menuLeft.toggleClass('pushmenu-open');
  });
});

This awesome jQuery plugin is developed by KonstantinBozhkov. For more Advanced Usages, please check the demo page or visit the official website.