Slick Slide Side Navigation with jQuery and CSS3

File Size: 3.32 KB
Views Total: 19692
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Slick Slide Side Navigation with jQuery and CSS3

Just another Mobile app-style side navigation menu that is sticky at the left side of your web page when toggled and pushes the main content section to the right with a full overlay. Built on top of Html5, CSS3 transitions & transforms and jQuery toggleClass method.

How to use it:

1. Create the Html for a side navigation with a toggle button.

<header>
  <div class="navBtn">+</div>
  <nav>
   <a href="">Home</a>
   <a href="">About</a>
   <a href="">Contact</a>
  </nav>
</header>

2. The required CSS to style the side navigation and make it responsive using CSS3 media queries.

/* 1024 */
@media only screen and (max-width: 1024px) {

header { width: 8%; }

}

/* 768 */
@media only screen and (max-width: 768px) {

header { width: 10%; }

}

/* 480 */
@media only screen and (max-width: 480px) {

.main { width: 90%; }


/* 320 */
@media only screen and (max-width: 320px) {
 header {
 width: 15%;
}
}

2. Create an overlay element that will cover the main content as the side navigation is open.

<div class="overlay"></div>

3. Style the overlay whatever you want.

.overlay {
  width: 100%;
  background: #384047;
  opacity: .85;
  z-index: 1;
  height: 100%;
  position: fixed;
  display: none;
}

4. Wrap the main content in a container element with CSS class of 'main'.

<div class="main">
  ...
</div>

5. The CSS styles to animate the 'push' behavior.

.push {
  margin-left: 240px;
  margin-right: -240px;
  transition: .3s ease-in;
}

6. Include the latest version of jQuery javascript library at the bottom of the page.

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

7. A little javacript to enable the side navigation using jQuery toggleClass method.

$(document).ready(function () {	

  var toggleMenu = function() {
	  $('header').toggleClass('toggle');
	  $('.main').toggleClass('push');
	  $('.overlay').toggleClass('block');
	  $('#social, .logo').toggleClass('reveal');
  };

	//Nav
	$('.navBtn').click(function() {
    toggleMenu();
	});

  Mousetrap.bind('esc', function() {
    toggleMenu();
  });

});

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