Minimalist Push Menu with jQuery and CSS/CSS3

Minimalist Push Menu with jQuery and CSS/CSS3
File Size: 362 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A mobile App style navigation jQuery script that pushes the body to reveal an off-canvas panel menu when you click on the toggle button.

How to use it:

1. Create a navigation list with a close button

<div class="menu"> 
  
  <div class="icon-close"> <img src="close.png"> </div>

  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">Blog</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Contact</a></li>
  </ul>
</div>

2. Create a trigger link to toggle the push menu.

<div class="icon-menu"> Menu </div>

3. Initial body & push menu styles.

body {
  left: 0;
  margin: 0;
  overflow: hidden;
  position: relative;
}

.menu {
  background: #202024;
  left: -285px;
  height: 100%;
  position: fixed;
  width: 285px;
}

4. Basic styles for the push menu.

.menu ul {
  border-top: 1px solid #636366;
  list-style: none;
  margin: 0;
  padding: 0;
}

.menu li {
  border-bottom: 1px solid #636366;
  font-family: 'Open Sans', sans-serif;
  line-height: 45px;
  padding-bottom: 3px;
  padding-left: 20px;
  padding-top: 3px;
}

.menu a {
  color: #fff;
  font-size: 15px;
  text-decoration: none;
  text-transform: uppercase;
}

.icon-close {
  cursor: pointer;
  padding-left: 10px;
  padding-top: 10px;
}

.icon-menu {
  color: #fff;
  cursor: pointer;
  font-size: 16px;
  padding-bottom: 25px;
  padding-left: 25px;
  padding-top: 25px;
  text-decoration: none;
  text-transform: uppercase;
}

.icon-menu i { margin-right: 5px; }

5. Load the necessary jQuery library at the bottom of the web page.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

6. The JavaScript to push the body and the navigation over by 285px over and push them back when the toggle link is clicked.

var main = function() {
  $('.icon-menu').click(function() {
    $('.menu').animate({
      left: "0px"
    }, 200);

    $('body').animate({
      left: "285px"
    }, 200);
  });

  $('.icon-close').click(function() {
    $('.menu').animate({
      left: "-285px"
    }, 200);

    $('body').animate({
      left: "0px"
    }, 200);
  });
};

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