Stacked Card Style Navigation Menu with jQuery and CSS3

Stacked Card Style Navigation Menu with jQuery and CSS3
File Size: 2.23 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

An awesome off-canvas navigation concept built with jQuery and CSS3 that allows you to switch between sectioned pages like stacked cards.

How to use it:

1. Create the sectioned content following the markup structure like this:

<div class="card-menu">
  <div class="card-menu__close-menu"></div>
  <div class="card-menu__section card-menu__section-1" data-section="1">
    <div class="card-menu__menu-btn"></div>
    <h2 class="card-menu__section-heading">Home</h2>
  </div>
  <div class="card-menu__section card-menu__section-2 active" data-section="2">
    <div class="card-menu__menu-btn"></div>
    <h2 class="card-menu__section-heading">About</h2>
  </div>
  <div class="card-menu__section card-menu__section-3 inactive" data-section="3">
    <div class="card-menu__menu-btn"></div>
    <h2 class="card-menu__section-heading">Contact</h2>
  </div>
  <div class="card-menu__section card-menu__section-4 inactive" data-section="4">
    <div class="card-menu__menu-btn"></div>
    <h2 class="card-menu__section-heading">Blog</h2>
  </div>
</div>

2. Style the hamburger icon to toggle the stacked pages.

.card-menu__close-menu {
  position: absolute;
  left: 22px;
  top: 22px;
  width: 29px;
  cursor: pointer;
}

.card-menu__close-menu:before, .card-menu__close-menu:after {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  width: 100%;
  height: 4px;
  background: #7097B0;
}

.card-menu__close-menu:before {
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
}

.card-menu__close-menu:after {
  -webkit-transform: rotate(-45deg);
  transform: rotate(-45deg);
}

.card-menu__menu-btn {
  position: absolute;
  left: 20px;
  top: 20px;
  width: 28px;
  height: 22px;
  -webkit-transition: opacity 0.2s 0.2s;
  transition: opacity 0.2s 0.2s;
  cursor: pointer;
}

.card-menu.menu-active .card-menu__menu-btn {
  pointer-events: none;
  opacity: 0;
  -webkit-transition: opacity 0.2s;
  transition: opacity 0.2s;
}

.card-menu__menu-btn:before {
  content: "";
  display: block;
  width: 100%;
  height: 3px;
  border-radius: 2px;
  background: currentColor;
  box-shadow: 0 8px, 0 16px;
}

3. The core CSS / CSS3 rules for the stacked pages..

.card-menu {
  overflow: hidden;
  position: absolute;
  width: 100%;
  height: 100%;
  background: #CDDBEE;
  border-radius: 6px;
}

.card-menu__section {
  z-index: 1;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  padding: 25px 0 0 65px;
  border-radius: inherit;
  -webkit-transition: -webkit-transform 0.4s;
  transition: -webkit-transform 0.4s;
  transition: transform 0.4s;
  transition: transform 0.4s, -webkit-transform 0.4s;
  -webkit-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
  will-change: transform;
}

.card-menu.menu-active .card-menu__section-1 {
  -webkit-transform: translate3d(20px, 60px, 0);
  transform: translate3d(20px, 60px, 0);
}

.card-menu__section-1.inactive {
  -webkit-transform: translate3d(100%, 60px, 0);
  transform: translate3d(100%, 60px, 0);
}

.card-menu.menu-active .card-menu__section-2 {
  -webkit-transform: translate3d(40px, 120px, 0);
  transform: translate3d(40px, 120px, 0);
}

.card-menu__section-2.inactive {
  -webkit-transform: translate3d(100%, 120px, 0);
  transform: translate3d(100%, 120px, 0);
}

.card-menu.menu-active .card-menu__section-3 {
  -webkit-transform: translate3d(60px, 180px, 0);
  transform: translate3d(60px, 180px, 0);
}

.card-menu__section-3.inactive {
  -webkit-transform: translate3d(100%, 180px, 0);
  transform: translate3d(100%, 180px, 0);
}

.card-menu.menu-active .card-menu__section-4 {
  -webkit-transform: translate3d(80px, 240px, 0);
  transform: translate3d(80px, 240px, 0);
}

.card-menu__section-4.inactive {
  -webkit-transform: translate3d(100%, 240px, 0);
  transform: translate3d(100%, 240px, 0);
}

.card-menu.menu-active .card-menu__section { cursor: pointer; }

.card-menu__section-heading {
  text-transform: uppercase;
  font-size: 12px;
  -webkit-transition: -webkit-transform 0.4s;
  transition: -webkit-transform 0.4s;
  transition: transform 0.4s;
  transition: transform 0.4s, -webkit-transform 0.4s;
}

.card-menu.menu-active .card-menu__section-heading {
  -webkit-transform: translateX(-45px);
  transform: translateX(-45px);
}

4. Load the needed jQuery JavaScript library at the end of the document.

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

5. The core JavaScript (jQuery script) to active the navigation menu.

var $demo = $(".card-menu");
var numOfSections = $(".card-menu__section").length;

$(document).on("click", ".card-menu__menu-btn", function() {
  $demo.addClass("menu-active");
});

$(document).on("click", ".card-menu__close-menu", function() {
  $demo.removeClass("menu-active");
});

$(document).on("click", ".card-menu.menu-active .card-menu__section", function() {
  var $section = $(this);
  var index = +$section.data("section");
  
  $(".card-menu__section.active").removeClass("active");
  $(".card-menu__section.inactive").removeClass("inactive");
  $section.addClass("active");
  $demo.removeClass("menu-active");
  
  for (var i = index + 1; i <= numOfSections; i++) {
    $(".card-menu__section[data-section="+ i +"]").addClass("inactive");
  }
});

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