<div id="left-flyout-nav" class="layout-left-flyout visible-sm"></div>
<div class="layout-right-content">
  <header class="the-header">
    <div class="navbar container">

      <!-- Trigger -->
      <a class="btn-navbar btn-navbar-navtoggle btn-flyout-trigger" href="#">
        <span class="icon-bar btn-flyout-trigger"></span>
        <span class="icon-bar btn-flyout-trigger"></span>
        <span class="icon-bar btn-flyout-trigger"></span>
      </a>

      <!-- Struktur -->
      <nav class="the-nav nav-collapse clearfix">
        <ul class="nav nav-pill pull-left">
          <li class="dropdown">
            <a href="#">Web Master <b class="caret"></b></a>
            <ul class="subnav">
              <li><a href="#">HTML5 & CSS3</a></li>
              <li><a href="#">Photoshop</a></li>
              <li><a href="#">PHP & MySQL</a></li>
            </ul>
          </li>
          <li class="dropdown">
            <a href="#">Web Design <b class="caret"></b></a>
            <ul class="subnav">
              <li><a href="#">HTML5 & CSS3</a></li>
              <li><a href="#">Photoshop</a></li>
              <li><a href="#">Javascript</a></li>
            </ul>
          </li>
          <li class="dropdown">
            <a href="#">PHP Framework<b class="caret"></b></a>
            <ul class="subnav">
              <li><a href="#">Codeigniter</a></li>
              <li><a href="#">Laravel</a></li>
              <li><a href="#">Yii</a></li>
              <li><a href="#">Zend</a></li>
            </ul>
          </li>
        </ul>
        <ul class="nav nav-pill pull-right">
          <li><a href="http://www.dumetschool.com">DUMET School</a></li>
          <li><a href="http://www.dumetschool.com/blog">Blog </a></li>
          <li><a href="http://www.dumetschool.com/tentang-kami">About Us </a></li>
        </ul>
      </nav>
    </div>
  </header>

  <main class="container">
    <h1>Navigasi Responsive dengan jQuery</h1>

    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    <p></p>
    <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
  </main>
</div>
<!-- END .layout-left-flyout -->
*{margin:0}

body {
  position: relative;
  overflow: hidden;
  width: 100%;
}

.layout-left-flyout {
  height: 100%;
  position: fixed;
  visibility: hidden;
  z-index: 0;
  transition: visibility 0 linear .2s;
  background: #383838;
  -webkit-perspective: 1000;
  -webkit-backface-visibility: hidden;
  -webkit-transform-style: preserve-3d;
}

.layout-left-flyout.isCbFlyNavActive {
  visibility: visible;
  transition: z-index 0 linear .2s;
  z-index: 1;
}

.cbFlyNav-wrap {
  display: block;
  position: relative;
  height: 100%;
  overflow: hidden;
  width: 270px;
  -webkit-perspective: 1000;
  -webkit-backface-visibility: hidden;
  -webkit-transform-style: preserve-3d;
}
.cbFlyNav-wrap > nav {
  transform: translateY(0);
  transition: transform 0 ease-in-out;
}

.nav-collapse {
  -webkit-transform: translate3d(0, 0, 0);
  -webkit-transform-style: preserve-3d;
}

.layout-right-content {
  transition: transform .2s ease-in-out;
  transform: translate3d(0, 0, 0);
  -webkit-perspective: 1000;
  -webkit-transform-style: preserve-3d;
  -webkit-backface-visibility: hidden;
  z-index: 1;
}

.layout-right-content.isCbFlyNavActive {
  transform: translate3d(270px, 0, 0);
  min-width: 320px;
}

.icon-cbmore {
  content: "";
  float: right;
  margin-top: 4.5px;
  padding: 4.5px;
  box-shadow: 1px -1px 0 0px #FFF inset;
  -webkit-transform: rotate(225deg);
}

.nav-flyout-navmask, .nav-flyout-contentmask {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

.nav-flyout-contentmask {
  z-index: 1;
}

.nav-flyout-navmask {
  right: 180px;
  z-index: 1;
}

.btn-navbar {
  position: absolute;
  width: 50px;
  height: 40px;
  padding: 4px 0;
  display: block;
  z-index: 1;
}

.btn-navbar-navtoggle {
  left: 10px;
}

.btn-navbar .icon-bar {
  display: block;
  width: 28px;
  height: 4px;
  background-color: #4d4d4d;
  margin: 7px auto 0 auto;
}

.btn-navbar .icon-bar + .icon-bar {
  margin-top: 3px;
}

@media screen and (min-width: 768px) {
  .btn-navbar {
    display: none;
  }
}

.navbar {
  height: 40px;
  margin: 0;
  padding: 5px 0;
  position: relative;
  background: #fff;
  margin-bottom: 10px;
  width: 100%;
  padding: 0 10px;
  font-family: "Lato", sans-serif;
  box-shadow: 0 1px 1px 0px #dddddd;
}

@media screen and (max-width: 767px) {
  .navbar .nav-collapse {
    display: none;
  }
}
@media screen and (min-width: 768px) {
  .navbar {
    height: auto;
    position: relative;
    background: #000;
    margin-bottom: 10px;
    width: 100%;
    padding: 0 10px;
  }
}

.the-nav ul.nav-flyout {
  display: block;
  margin-bottom: 15px;
  float: none;
  height: 100%;
}
.the-nav ul.nav-flyout > li {
  float: none;
  display: block;
  width: 270px;
}
.the-nav ul.nav-flyout li a {
  color: #FFF;
  display: block;
  text-decoration: none;
  padding: 11px 15px;
  margin-right: 0;
}
.the-nav ul.nav-flyout li a:hover {
  background: #ff8358;
}
.the-nav ul.nav-flyout .dropdown {
  position: static;
}
.the-nav ul.nav-flyout .dropdown .subnav {
  float: none;
  position: absolute;
  display: block;
  top: 0;
  right: 0;
  left: auto;
  width: 0;
  min-width: 0;
  margin: 0;
  list-style: none;
  z-index: 1000;
  background: #595959;
  transition: width .2s ease-in-out;
}
.the-nav ul.nav-flyout .dropdown .subnav > li {
  width: 180px;
}
.the-nav ul.nav-flyout .dropdown .subnav.is-subnav-visible {
  width: 180px;
}
.the-nav.is-inactive ul.nav-flyout > li > a {
  opacity: .2;
}
.the-nav.is-inactive ul.nav-flyout > li.is-active > a {
  opacity: 1;
  background: #ff8358;
}


@media screen and (min-width: 768px) {
  .container {
    width: 95%;
    margin: 0 auto;
  }

  .the-nav {
    display: block;
  }

  .the-nav .nav {
    display: block;
  }

  .the-nav .nav-pill:after {
    content: "";
    display: table;
    clear: both;
  }

  .the-nav > .nav {
    margin: 0;
    line-height: normal;
  }

  .the-nav > .nav > li {
    display: inline-block;
    margin-bottom: 0;
    position: relative;
  }

  .the-nav > .nav > li .caret {
    margin-top: 8px;
    margin-left: 2px;
    border-top-color: #A7A7A7;
    border-bottom-color: #A7A7A7;
  }

  .the-nav > .nav > li a {
    display: block;
    padding: 10px 10px 10px;
    color: #A7A7A7;
    font-weight: 500;
    text-decoration: none;
  }

  .the-nav > .nav > li:nth-of-type(1) > a {
    padding-left: 0;
  }

  .the-nav > .nav > li:last-of-type > a {
    padding-right: 0;
  }

  
  .the-nav > .nav > li:hover > a {
    color: #fff;
  }

  .the-nav > .nav > li:hover .subnav {
    display: block;
  }

  .the-nav > .nav > li:hover .caret {
    border-top-color: #303030;
    border-bottom-color: #303030;
  }

  
  .nav > li > .subnav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 20;
    margin: 0;
    padding: 0;
    min-width: 160px;
    background: #F7F7F7;
    box-shadow: 0 1px 1px 0px #DDDDDD;
  }

  .nav > li > .subnav > li {
    margin-bottom: 0;
  }

  .nav > li > .subnav > li a {
    color: #A7A7A7;
    transition: all .2s;
  }

  .nav > li > .subnav > li:hover a {
    background: #ff8358;
    color: white;
  }
}

.hidden-sm {
  display: none;
}

@media screen and (min-width: 768px) {
  .visible-sm {
    display: none;
  }

  .hidden-sm {
    display: block;
  }
}

*, *:before, *:after {
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

body {
  background: #333;
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
ul li {
  margin: 0;
}

.pull-left {
  float: left;
}

.pull-right {
  float: right;
}

.dropdown .caret {
  display: inline-block;
  width: 0;
  height: 0;
  vertical-align: top;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid gray;
  content: "";
}

.clearfix:after {
  content: "";
  display: table;
  clear: both;
}

.container {
  font-family: 'Lato', Sans-serif;
  width: 95%;
  margin: 0 auto;
}
.container.navbar {
  width: 100%;
}
.container:before, .container:after {
  content: "";
  display: table;
  clear: both;
}

h1 {
  font-size: 3.7em;
  font-weight: 200;
  margin-top: .2em;
}

p {
  font-size: 1em;
  line-height: 1.4em;
  font-weight: 400;
}

.align-center {
  text-align: center;
}

pre {
  color: #cccccc;
  overflow: auto;
  overflow: auto;
  background: #1D1F21;
  padding: 0;
  font-family: monospace;
  -moz-tab-size: 2;
  -o-tab-size: 2;
  tab-size: 2;
  -ms-word-break: normal;
  word-break: normal;
  word-break: normal;
  -webkit-hyphens: none;
  -moz-hyphens: none;
  -ms-hyphens: none;
  hyphens: none;
  position: relative;
}
pre code {
  background: none;
  padding: 15px;
  white-space: pre;
  overflow: auto;
  display: block;
}

.layout-right-content {
  color: #fff;
}
;(function ( $, window, document, undefined ) {
  
  $body = $( 'body' );
  
  $.cbFlyNav = function( options, element ) {
		this.$el = $( element );
		this._init( options );
	};
 
  $.cbFlyNav.defaults = {
    trigger: '.btn-flyout-trigger'
    ,cbNavWrapper: '#left-flyout-nav'
    ,cbContentWrapper: '.layout-right-content'
    ,minWidth: 768
	};
  
  $.cbFlyNav.prototype = {
  
    _init : function( options ) {
      this.options = $.extend({}, $.cbFlyNav.defaults, options);
      
      //Cache elements and intit variables
      this._config();
      
      //Initialize event listenters
      this._initEvents();
    },
    
    _config : function() {
			this.open = false;
      this.copied = false;
      this.windowWith = $(window).width();
      this.subNavOpen = false;
      this.wasOpened = false;
      this.$cbWrap = $('<div class="cbFlyNav-wrap"></div>');
      this.$trigger = $(this.options.trigger);
      this.$regMenus = this.$el.children( 'ul.nav.nav-pill' );
      this.$newMenus = $(this.$el.clone());
      this.$contentMask = $('<a class="nav-flyout-contentmask" href="#"></a>');
      this.$navMask = $('<a class="nav-flyout-navmask" href="#"></a>');
      this.$openSubnav = "";
		},
    
    _initEvents : function() {
      var self = this; 
      
      self.$trigger.on('click.cbFlyNav', function(e) {
        e.stopPropagation();
        
        if ( !self.open ) {
          if ( !self.copied ) {
            self._copyNav();
          }
          self._openNav();
        }
        else {
          self._closeNav();
        }
        self.wasOpened = true;
        
        //console.log('WasOpened: '+self.wasOpened+ '. Open? '+self.open);
      });
      
      //Hide menu when window is bigger than allowed minWidth
      $(window).on('resize', function() {
        var windowWidth = $(window).width();
        if(self.open && windowWidth > self.options.minWidth){
          self._closeNav();
        }
      });
      
      //Hide menu when body clicked. Usign an a tag to mask content.
      self.$contentMask.on('click.cbFlyNav', function( e ) {
        e.preventDefault();
        self._closeNav();
      });
      
      self.$navMask.on('click.cbFlyNav', function( e ) {
        e.preventDefault();
        self._closeSubNav();
      });
      
      //Handle clicks inside menu
      self.$newMenus.on( 'click.cbFlyNav', function( e ) {
        e.stopPropagation();
        var $menu = $(this);
        
        //console.log("Menu clicked");
      });
      
      //Handle menu item clicks
      self.$newMenus.children().find('li').on('click.cbFlyNav', function(e) {
        e.stopPropagation();
        var $item = $(this),
            $subnav = $item.find('ul.subnav');
        
        if ($subnav.length > 0) {
          //item with subnav clicked
          
          //console.log("Item with subnav clicked");

          $subnav.css('height', window.innerHeight);
          self._openSubNav($subnav);
        }
        else {
          //item without subnav clicked
          //console.log("Item without subnav clicked");
        }
      });
      
    },
    
    _copyNav : function() {
      var self = this;
      console.log("copying nav");
      
      var newWrap = $('<div class="cbFlyNav-wrap"></div>');
      self.$newMenus.children( 'ul.nav.nav-pill' ).each(function() {
        $this = $(this);
        $this.removeClass('nav-pill').addClass('nav-flyout');
        $this.find('.caret').replaceWith('<i class="icon-cbmore"></i>')
      });
            
      $(self.options.cbNavWrapper).prepend(self.$cbWrap.prepend(self.$newMenus));
      self.copied = true;
     
    },
    
    openNav : function() {
      if ( !this.open ) {
        this._openNav();
      }
    },
    
    _openNav : function() {
      var self = this;
      console.log("Opening Nav");
        
      $(self.options.cbNavWrapper).addClass('isCbFlyNavActive');
      $(self.options.cbContentWrapper)
                        .addClass('isCbFlyNavActive')
                        .append(self.$contentMask);

      self.open = true;
    },
    
    closeNav : function() {
      if ( !this.close ) {
        this._closeNav();
      }
    },
    
    _closeNav : function() {
      var self = this;
      console.log("Closing Nav");
      
      $(self.options.cbNavWrapper).removeClass('isCbFlyNavActive');
      $(self.options.cbContentWrapper).removeClass('isCbFlyNavActive');
      
      if(self.subNavOpen) {
        self._closeSubNav();
      }
      self.$contentMask.detach();

      self.open = false;
    },
    
    _openSubNav : function($subnav) {
      var self = this,
          $parent = $subnav.parent('li');
          
      $subnav.addClass('is-subnav-visible');
      $parent.addClass('is-active');
      self.$newMenus.addClass('is-inactive');
      self.$cbWrap.append(self.$navMask);
      
      $subnav.on('click.cbFlyNav', function(e) {
        e.stopPropagation();
      });
      
      self.$openSubnav = $subnav;
      self.subNavOpen = true;
    },

    _closeSubNav : function() {
      var self = this,
          $parent = self.$openSubnav.parent('li');
      
      self.$openSubnav.removeClass('is-subnav-visible');
      $parent.removeClass('is-active');
      self.$newMenus.removeClass('is-inactive');
      self.$navMask.detach();
      
      self.$openSubnav.off('click.cbFlyNav');
      
      self.$openSubnav = "";
      self.subNavOpen = false;
    }
  };
  
  
  $.fn.cbFlyout = function ( options ) {
    this.each(function() {	
      var instance = $.data( this, 'cbFlyout' );
      if ( instance ) {
        instance._init();
      }
      else {
        instance = $.data( this, 'cbFlyout', new $.cbFlyNav( options, this ) );
      }
    });
    
    return this;
  }
  
}(jQuery, window, document));

$(document).ready(function(){
  $('.the-nav').cbFlyout();
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js