Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <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>
      
      <!-- Structure -->
      <nav class="the-nav nav-collapse clearfix">
        <ul class="nav nav-pill pull-left">
          <li class="dropdown">
            <a href="#">Dogs <b class="caret"></b></a>
            <ul class="subnav">
              <li><a href="#">Terrier</a></li>
              <li><a href="#">Labrador</a></li>
              <li><a href="#">Pitbull</a></li>
              <li><a href="#">German Shephard</a></li>
              <li><a href="#">Chihuahua</a></li>
              <li><a href="#">Beagle</a></li>
            </ul>
          </li>
          <li class="dropdown">
            <a href="#">Cats  <b class="caret"></b></a>
            <ul class="subnav">
              <li><a href="#">Persian</a></li>
              <li><a href="#">Siamese</a></li>
              <li><a href="#">Ragdoll</a></li>
              <li><a href="#">Lion</a></li>
              <li><a href="#">Tiger</a></li>
            </ul>
          </li>
          <li class="dropdown">
            <a href="#">Primates  <b class="caret"></b></a>
            <ul class="subnav">
              <li><a href="#">Monkey</a></li>
              <li><a href="#">Lemur</a></li>
              <li><a href="#">Gorilla</a></li>
              <li><a href="#">Chimpanzee</a></li>
            </ul>
          </li>
          <li class="dropdown">
            <a href="#">Reptiles  <b class="caret"></b></a>
            <ul class="subnav">
              <li><a href="#">Boa</a></li>
              <li><a href="#">Monitor Lizard</a></li>
              <li><a href="#">Comodo Dragon</a></li>
              <li><a href="#">Iguana</a></li>
              <li><a href="#">Alligator</a></li>
            </ul>
          </li>
        </ul>
        <ul class="nav nav-pill pull-right">
          <li><a href="#">Congress </a></li>
          <li><a href="#">Blog </a></li>
          <li><a href="#">Contact Us </a></li>
        </ul>
      </nav>
    </div>
  </header>
  
  <main class="container">
    <h1>Responsive Off Screen Navigation jQuery Plugin</h1>
    
    <p>Effective Responsive navigation patterns are so hard to find nowdays. There are so many of them. They look promising, but a lot of the time when you get into actually beggining to use one, it bites you in the behind.</p>
    
    <p>I've gone ahead and made a nice jQuery plugin to give people more options. I could sit here and try to describe with words what it does but this is a demo, and you're already here, so just go ahead and play with it.</p>
    
    <h3 class="align-center">&rarr; RESIZE THE SCREEN! &larr;</h3>
    
    Markup structure is limited as of now (will-change in the future if demand is high)
    <pre><code>
&lt;div class=&quot;layout-left-flyout visible-sm&quot;&gt;&lt;/div&gt;<br/>&lt;div class=&quot;layout-right-content&quot;&gt;<br/>  &lt;header class=&quot;the-header&quot;&gt;<br/>    &lt;div class=&quot;navbar container&quot;&gt;<br/><br/>      &lt;!-- Trigger --&gt;<br/>      &lt;a class=&quot;btn-navbar btn-navbar-navtoggle btn-flyout-trigger&quot; href=&quot;#&quot;&gt;<br/>        &lt;span class=&quot;icon-bar btn-flyout-trigger&quot;&gt;&lt;/span&gt;<br/>        &lt;span class=&quot;icon-bar btn-flyout-trigger&quot;&gt;&lt;/span&gt;<br/>        &lt;span class=&quot;icon-bar btn-flyout-trigger&quot;&gt;&lt;/span&gt;<br/>      &lt;/a&gt;<br/><br/>      &lt;!-- Structure --&gt;<br/>      &lt;nav class=&quot;the-nav nav-collapse clearfix&quot;&gt;<br/>        &lt;ul class=&quot;nav nav-pill pull-left&quot;&gt;<br/>          &lt;li class=&quot;dropdown&quot;&gt;<br/>            &lt;a href=&quot;#&quot;&gt;Dogs &lt;b class=&quot;caret&quot;&gt;&lt;/b&gt;&lt;/a&gt;<br/>            &lt;ul class=&quot;subnav&quot;&gt;<br/>              &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Terrier&lt;/a&gt;&lt;/li&gt;<br/>              &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Labrador&lt;/a&gt;&lt;/li&gt;<br/>              ...<br/>            &lt;/ul&gt;<br/>          &lt;/li&gt;<br/>          &lt;li class=&quot;dropdown&quot;&gt;<br/>            &lt;a href=&quot;#&quot;&gt;Cats  &lt;b class=&quot;caret&quot;&gt;&lt;/b&gt;&lt;/a&gt;<br/>            &lt;ul class=&quot;subnav&quot;&gt;<br/>              &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Persian&lt;/a&gt;&lt;/li&gt;<br/>              &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Siamese&lt;/a&gt;&lt;/li&gt;<br/>              ...<br/>            &lt;/ul&gt;<br/>          &lt;/li&gt;<br/>          &lt;li class=&quot;dropdown&quot;&gt;<br/>            &lt;a href=&quot;#&quot;&gt;Primates  &lt;b class=&quot;caret&quot;&gt;&lt;/b&gt;&lt;/a&gt;<br/>            &lt;ul class=&quot;subnav&quot;&gt;<br/>              &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Monkey&lt;/a&gt;&lt;/li&gt;<br/>              ...<br/>            &lt;/ul&gt;<br/>          &lt;/li&gt;<br/>        &lt;/ul&gt;<br/>        &lt;ul class=&quot;nav nav-pill pull-right&quot;&gt;<br/>          &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Congress &lt;/a&gt;&lt;/li&gt;<br/>          ...<br/>        &lt;/ul&gt;<br/>      &lt;/nav&gt;<br/>    &lt;/div&gt;<br/>  &lt;/header&gt;<br/>  &lt;main class=&quot;container&quot;&gt;<br/>    ...<br/>  &lt;/main&gt;<br/>&lt;/div&gt;&lt;!-- END .layout-left-flyout --&gt;
  </code></pre>    

    <br />
And the JavaScript
<pre><code>$('.the-nav').cbFlyout( minWidth: 768 );
</code></pre>
    
    <p>Added <code> minWidth </code> option to specify a minimum width to allow the nav to be remain active.</p>
    <p>As of now the code might still be messy. I'll dump it on github and if people submit issues I'll try to keep it updated. For now you can just copy the layout on this pen.</p>
    
    <br /></be>
    <h3 class="align-center"><a class="gh-btn" href="https://github.com/jalvarado91/cbFlyout">Check on github</a></h3>
    
    <br /><br />
  </main>
</div><!-- END .layout-left-flyout -->
              
            
!

CSS

              
                @import "compass/css3";

/* cbFlyNav Req Styles */


body {
  /* These styles don't have to be on body,
     they could be on an element that wraps around
     the left-flyout-nav and the content. 
     This is to prevent a problem on Chrome that
     leaves the width of the container with the 
     added width of the flyout nav even after it's been
     hidden. */
  position: relative;
  overflow-x: 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;
  > nav {
    transform: translateY(0);
    transition: transform 0 ease-in-out;
/*    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;*/
  }
}

.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;
  /* NOTE! Put container bg here so you don't
     get any clipping when the content is 
     transitioning. Any tips on alternate 
     solutions are welcome.
  */
  background: #fff;
  background: #E72534;
}
.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;
}
/* Menu Toggle */

.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 Styles */
.navbar {
  height: 40px;
  margin: 0;
  padding: 5px 0;
  position: relative;
  background: #fafafa;
  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: #fafafa;
    margin-bottom: 10px;
    width: 100%;
    padding: 0 10px;
    
  }
}

/* Mobile First Nav */
.the-nav {
  ul.nav-flyout {
    display: block;
    margin-bottom: 15px;
    float: none;
    height: 100%;
    > li {
      float: none;
      display: block;
      width: 270px;
    }
    li {
      a {
        color: #FFF;
        display: block;
        text-decoration: none;
        padding: 11px 15px;
        margin-right: 0;
        &:hover {
          background: #ff8358;
        }
      }
    }
    .dropdown {
      position: static;
      .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;
        >li {
            width: 180px;
        }
        &.is-subnav-visible {
          width: 180px;
        }
      }
    }
  }
  &.is-inactive ul.nav-flyout{
    > li {
      > a {
        opacity: .2;
      }
      &.is-active > a {
        opacity: 1;
        background: #ff8358;
      }
    }
  }
}

/* Large Screen Styles*/ 
@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;
  }

  /* Active State */ 
  .the-nav > .nav > li:hover > a {
    color: #303030;
  }
  .the-nav > .nav > li:hover .subnav {
    display: block;
  }

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

  /* Subnav */ 

  .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;
  }
}

/* General Mobile First Styles */ 

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

/* Resets and clean ups and extras */

*, *:before, *:after {
  @include box-sizing(border-box);
}

body {
  background: #E72534;
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
  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;
  &.navbar {
    width: 100%;
  }

  &:before, &: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;
}
a.gh-btn {
  display: inline-block;
  width:250px;
  background: white;
  color: #1D1F21;
  font-weight: bold;
  text-transform: uppercase;
  text-decoration: none;
  text-align: center;
  padding: 15px 25px;
  transition: all .2s ease-in-out;
  &:hover {
    background: #e6e6e6;
  }
}
.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;
  
  code {
    background: none;
    padding: 15px;
    white-space: pre;
    overflow: auto;
    display: block;
  }
}
.layout-right-content {
  
  color: #ffdede;
}

@import url(https://fonts.googleapis.com/css?family=Lato:300,400,700);
              
            
!

JS

              
                ;(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();
});
              
            
!
999px

Console