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

              
                html
  head
    meta(name="viewport", content="width=device-width")
  body
    nav
      ul
        li: a(href="#") Link 1
        li: a(href="#") Link 2
        li: a(href="#") Link 3
    article
      p Scroll this box down, and you'll see the nav moves out of view.
      p If you then scroll up, the nav will scroll into view, in a 1:1 transition with the scrolling motion.
      p I felt the jarring nature of some of the other sticky-header show/hide patterns out there could be improved upon, so tried to build something more like Safari on iOS's behaviour.
      p Let me know what you think! 
        a(href="https://twitter.com/_iest") @iest
        |  on twitter
              
            
!

CSS

              
                @import "nib"

*
  box-sizing border-box
body
  font-family "Helvetica Neue"
  font-weight 200
  max-width 40em
  position relative
  margin 0 auto
  margin-top 2em

nav
  background #BA42D7
  margin 0 auto
  padding 0.5em
  position fixed
  top 0
  width 40em

  ul
    margin 0
    padding 0
  li
    list-style none
    display inline-block
  a
    color rgba(#fff, 0.9)
    text-decoration none

article
  background #f5f5f5
  color #333
  width 100%
  padding 0.5em
  font-size 3em


              
            
!

JS

              
                // Used jQuery just to slap it together quickly
// Could very easily use vanilla JS for this

var $nav = $("nav");
var navHeight = $nav.outerHeight();

var lastScrollTop = $(this).scrollTop();
var navTranslate = 0;

function scrolledDown(amount) {
  if (navTranslate < navHeight) {
    navTranslate = navTranslate + amount;
  } else {
    navTranslate = navHeight;
  }
}

function scrolledUp(amount) {
  if (navTranslate > 0) {
    navTranslate = navTranslate - amount;
  } else {
    navTranslate = 0;
  }
}


$(window).scroll(function() {
  var st = $(this).scrollTop();

  if (st < 0) return;

  if (st > lastScrollTop){
     scrolledDown(st - lastScrollTop);
  } else {
     scrolledUp(lastScrollTop - st);
  }
  
  lastScrollTop = st;

  $nav.css({
    "-webkit-transform": "translateY("+-navTranslate+"px)"
  });
});
              
            
!
999px

Console