Fullscreen Curtain Menu With jQuery And CSS3 Animations

Fullscreen Curtain Menu With jQuery And CSS3 Animations
File Size: 2.49 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A fancy site navigation that displays a fullscreen, mobile-friendly overlay menu with curtain close / reveal effects using CSS3 animations and a little jQuery script.

How to use it:

1. In this case, we're going to use the Material Design Iconic Font for menu toggle icons.

<link href="/path/to/material-design-iconic-font.min.css" rel="stylesheet">

2. Create the html for the menu toggle button.

<span class="menu-trigger trigger icon icon-menu" rel="nav-overlay"></span>

3. Create the fullscreen overlay menu from a nav list.

<div id="nav-overlay">
  <nav>
    <li><a href="#">Home</a></li>
    <li><a href="#">Blog</a></li>
    <li><a href="#">Contact</a></li>
    <li><a href="#">About</a></li>
  </nav>
</div>

4. Style the menu toggle button.

.menu-trigger {
  cursor: pointer;
  position: fixed;
  padding: 1rem;
  top: 0;
  right: 0;
  z-index: 100;
  color: black;
  -webkit-transform: rotate(225deg);
  transform: rotate(225deg);
  -webkit-transition: all 350ms ease;
  transition: all 350ms ease;
}

.menu-trigger.open {
  color: white;
  -webkit-transform: rotate(0deg);
  transform: rotate(0deg);
}

.icon {
  display: inline-block;
  font: normal normal normal 14px/1 'Material-Design-Iconic-Font';
  font-size: inherit;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.icon.icon-menu:before {
  content: '\f136';
  font-size: 3rem;
}

5. The primary CSS/CSS3 styles for the fullscreen overlay menu.

#nav-overlay {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}

#nav-overlay nav {
  width: 100%;
  overflow: hidden;
  position: absolute;
  top: -100%;
  left: 0;
  width: 100%;
  height: 100%;
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -webkit-flex-direction: column;
  -ms-flex-direction: column;
  flex-direction: column;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  -ms-flex-pack: center;
  justify-content: center;
  list-style: none;
  z-index: 90;
  -webkit-transition: top 350ms ease;
  transition: top 350ms ease;
}

#nav-overlay nav li {
  display: block;
  text-align: center;
  margin: 1rem 0;
}

#nav-overlay nav a, #nav-overlay nav a:visited {
  font-size: 3rem;
  font-weight: 400;
  letter-spacing: 15px;
  line-height: 1.25;
  text-transform: uppercase;
  text-decoration: none;
  color: white;
}

#nav-overlay nav a:hover, #nav-overlay nav a:focus, #nav-overlay nav a:visited, #nav-overlay nav a:visited:hover, #nav-overlay nav a:visited:focus, #nav-overlay nav a:visited:visited { text-decoration: underline; }

#nav-overlay.open nav { top: 0; }

#nav-overlay:before, #nav-overlay:after {
  content: "";
  position: absolute;
  z-index: 50;
  top: 0;
  height: 100%;
  width: 100%;
  background: blue;
  transition: transform 350ms, -webkit-transform 350ms;
  background-image: url(bg.jpg);
  background-size: cover;
  background-repeat: repeat;
  background-position: center center;
}

#nav-overlay:before {
  left: 0;
  -webkit-transform: skew(50deg) translateX(-200%);
  transform: skew(50deg) translateX(-200%);
  clip: rect(auto 50vw auto auto);
}
@media (min-width: 500px) {

#nav-overlay:before {
  -webkit-transform: skew(50deg) translateX(-150%);
  transform: skew(50deg) translateX(-150%);
}
}

#nav-overlay.open:before {
  -webkit-transform: skew(0) translateX(0%);
  transform: skew(0) translateX(0%);
}

#nav-overlay:after {
  right: 0;
  -webkit-transform: skew(50deg) translateX(200%);
  transform: skew(50deg) translateX(200%);
  clip: rect(auto auto auto 50vw);
}
@media (min-width: 500px) {

#nav-overlay:after {
  -webkit-transform: skew(50deg) translateX(150%);
  transform: skew(50deg) translateX(150%);
}
}

#nav-overlay.open:after {
  -webkit-transform: skew(0) translateX(0%);
  transform: skew(0) translateX(0%);
}

6. Put the latest version of jQuery library at the bottom of the webpage.

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

7. The jQuery script to active the Fullscreen Curtain Menu.

$(document).ready(function() {
  $('.trigger').click(function() {
    var $this = $(this),
    notThis = $this.hasClass('open'),
    thisNav = $this.attr("rel");
    if (!notThis) {
     $('.triggered-area, .trigger').removeClass('open');
     if ( $( '.trigger' ).hasClass( "block-scroll" ) ){
      $('html').removeClass('disable-scroll');
      $('#overlay-mobile').removeClass('visible');
     }
    }
    $this.toggleClass('open');
    $("#"+thisNav).toggleClass('open');
    if ( $( this ).hasClass( "block-scroll" ) ){
     $('html').toggleClass('disable-scroll');
     $('#overlay-mobile').toggleClass('visible');
    }
  });
  $(document).on('click', function(event) {
    if (!$(event.target).closest('.triggered-area, .trigger').length) {
     $('.triggered-area, .trigger').removeClass('open');
     if ( $( '.trigger' ).hasClass( "block-scroll" ) ){
      $('html').removeClass('disable-scroll');
      $('#overlay-mobile').removeClass('visible');
     }
    }
  });
});

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