css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <header>
  Scroll to show/hide this bar!
</header>

<div class="content">
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eleifend tempor elit ut imperdiet. In adipiscing sed metus non vehicula. Nullam a odio a lorem rutrum volutpat. Praesent fringilla pellentesque erat laoreet adipiscing. Nam porttitor pellentesque est, at condimentum purus. Duis vel volutpat libero. Donec vitae dui mi. Nulla commodo nunc a pretium porta. Praesent tempor nunc vel risus semper, eget viverra felis mattis. Donec sit amet ante tristique, porta magna quis, faucibus ligula. Donec consectetur ligula leo, eu ornare purus placerat at.
  </p>
  <p>
    Nullam eget lacus vel mauris tempus cursus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Cras elementum sagittis pharetra. Sed quis ante auctor, facilisis nisl in, lacinia tellus. Aliquam consequat, eros nec iaculis rhoncus, neque nibh luctus nunc, ac interdum libero nibh at lectus. In id bibendum diam. Cras consectetur ultricies leo, id pulvinar nisi cursus sit amet. Donec elementum magna nec lorem laoreet tincidunt. Sed ut leo mollis lectus egestas lobortis at consequat mauris. Donec pharetra sapien massa, non auctor diam porta et. Aenean aliquam erat augue, gravida posuere ipsum elementum nec. Quisque convallis nisl eget nunc aliquam bibendum. Nulla facilisi. Vivamus sollicitudin in neque eu feugiat. Proin quis orci vitae orci rhoncus porta.
 </p>
  <p>
Aenean sagittis ornare consequat. Ut nunc enim, cursus at vehicula eu, tempor a ipsum. Phasellus vel feugiat est. Morbi aliquet scelerisque tristique. Fusce auctor ut eros at accumsan. Fusce neque erat, tincidunt et porta sodales, sodales id risus. Morbi turpis libero, tincidunt eu placerat ornare, pulvinar sed ipsum. Quisque suscipit velit eu nunc venenatis, quis venenatis elit varius. Etiam laoreet neque sapien, ut interdum magna adipiscing blandit. Vestibulum molestie sem ac elit eleifend, vitae accumsan nulla pharetra. Aliquam erat volutpat. Duis mollis sagittis ante. Etiam sollicitudin, justo eu mattis tincidunt, mauris lorem interdum dolor, vitae tincidunt mi neque convallis eros. Ut lacinia massa in consequat sagittis. Fusce pulvinar risus ac est porta consectetur.
  </p><p>
Nunc scelerisque fermentum tempus. Duis fringilla sagittis massa et viverra. Pellentesque vel auctor augue, non hendrerit dolor. Duis convallis venenatis sem sed iaculis. Vivamus at dui malesuada, laoreet arcu sit amet, vulputate ipsum. Curabitur nisl arcu, eleifend vitae malesuada et, lobortis ac sem. Fusce sit amet aliquam ante, a placerat lectus. Aenean feugiat quis libero et vestibulum. Quisque condimentum leo in vehicula pulvinar. Nam quam tortor, consectetur eu rhoncus ut, sagittis pharetra lacus. Proin at rutrum purus. Aliquam elementum dolor non libero porttitor feugiat. Nunc placerat imperdiet fringilla. Nullam nunc libero, hendrerit eu arcu quis, rutrum fringilla dui.
  </p><p>
Praesent et ante in mauris auctor elementum vitae in mi. Proin lobortis aliquam ipsum, eget congue nibh commodo ac. Proin interdum, quam id eleifend fringilla, odio turpis vehicula dui, eleifend pretium urna erat eget sapien. Curabitur at metus et nisl placerat pulvinar. Curabitur eu lectus ac erat tristique venenatis a ullamcorper urna. Sed sed felis imperdiet, condimentum enim non, porta neque. Mauris molestie auctor viverra. Nulla viverra sodales felis, vel hendrerit augue semper eu. Ut laoreet non tellus eget convallis. Nulla sagittis nisl urna, non imperdiet neque laoreet eget. Duis blandit quam est, ac rhoncus arcu aliquet a. Nullam ut turpis nisl.
  </p>
</div>
            
          
!
            
              @import "compass/css3";

header {
  $h: 50px;
  width: 100%;
  height: 100%;
  max-height: $h;
  position: absolute;
  top: 0;
  overflow: hidden;
  z-index: 100;
  transform: translate3d(0,0,0);
  transition-duration: .2s;
  transition-property: opacity,transform,background;
  transition-timing-function: ease-in-out;
  backface-visibility: hidden;
  perspective: 1000;
  left: 0px;
  right: 0px;
  text-align: center;
  background: white;
  color: #4183c4;
  line-height: $h;
  
  &.hidden {
    opacity: 0;
    transition-duration: .25s;
    transform: translate3d(0,-$h,0);
  }
  &.fixed {
    box-shadow: 0 1px 1px rgba(0,0,0,0.2);
    position: fixed;
    opacity: 1;
  }
  &:hover {
    opacity: 1 !important;
    transform: translate3d(0,0,0);
  }
}

.content {
  height: 2000px;
  background: #ddd;
  padding: 100px 40px;
}

            
          
!
            
              $.fn.shynav = function(opts) {
  var elem = this;

  var defaults = {
    delay: 4000,
    minScroll: $(elem).height() || 0,
    detachedClass: 'scrolled',
    hiddenClass: 'hidden'
  };
  
  var opts = $.extend(defaults, opts);

  var nav = {
    el: $(elem),
    
    show: function() {
      this.el.removeClass(opts.hiddenClass);
      this.checkInteraction();
    },
    
    hide: function() {
      this.el.addClass(opts.hiddenClass);
    },
    
    checkInteraction: function() {
      var self = this;
      
      if (this.timer) clearTimeout(this.timer);
      this.timer = setTimeout(function() {
        if (self.isScrolled()) {
          self.hide();
        }
        return false;
      }, opts.delay);
    },
    
    isHidden: function() {
      return this.el.hasClass(opts.hiddenClass);
    },
    
    isScrolled: function() {
      return ($(window).scrollTop() > opts.minScroll);
    },
    
    handle: function(direction) {
      if (this.isScrolled()) {
        this.el.addClass(opts.detachedClass);
      } else {
        this.el.removeClass(opts.detachedClass);
      }
      
      if (direction == 'down') {
        if (this.isScrolled()) this.hide();
      } else if (this.isHidden()) {
        this.show();
      }
      
      this.scrollTop = $(window).scrollTop();
    }
  };

  // init binding
  $(window).scroll(function(){
    var scrollDirection = ($(this).scrollTop() >= nav.scrollTop) ? 'down' : 'up';
    nav.handle(scrollDirection);
  });
}

//usage
$('header').shynav({
  delay: 4000,
  minScroll: 0,
  detachedClass: 'fixed'
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console