Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

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

              
                <h1>This is a sticky page!</h1>
<div class="page page-bg-blue sticky-page">
  <h1>page one</h1>
</div>

<div class="page page-bg-red sticky-page">
  <h1>page two</h1>
</div>

<div class="page page-bg-green sticky-page">
  <h1>page three</h1>
</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;  
}

html, body {
  min-height: 100%;
  margin: 0;
  overflow: auto;
  font-family: sans-serif;
  position: relative;
}

h1 {
  text-align: center;
  margin: 5em 0;
}

.page {
  width: 100%;
  height: 1000px;
  margin: 0;
  border: 20px solid white;
  padding: 1em;
  background: #ccc;
  text-align: center;
  position: relative;
  box-shadow: 0 0 20px rgba(0,0,0,0.2);
}

.page h1 {
  text-transform: uppercase;
  color: white;
  display: inline-block;
  position: relative;
  margin: 1em 0 0;
}

.page h1:after {
  content: '';
  width: 100%;
  position: absolute;
  top: 120%;
  opacity: 0.5;
  border-bottom: 2px solid #fff;
  display: block;
}

.page.page-fixed {
  position: fixed !important;
  top: 0 !important;
  left: 0;
  right: 0;
}

.page-bg-green {
  background: #42d472;
}

.page-bg-blue {
  background: #42c4d4;
}

.page-bg-red {
  background: #d44242;
}
              
            
!

JS

              
                
$(document).ready(function(){
  var w=window,d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],x=w.innerWidth||e.clientWidth||g.clientWidth,y=w.innerHeight||e.clientHeight||g.clientHeight,
      pages = d.getElementsByClassName('sticky-page'),
      pagesCache = {};
   
  // prevent body from collapsing when pages are pinned
  $('body').css({'height' : $('body').height() })

  for (var i = pages.length; i--; ) {
    console.log(pages[i])
    var _this = pages[i],
        top = _this.offsetTop // calculate this now, but apply later
    
    _this.style.zIndex = 1000*i+100 // layer properly
    _this.style.height = y + "px"
    _this.style.top = top + "px"
    _this.style.position = "absolute"
    
    // cache it
    pagesCache['page'+i] = { "node": _this, "offset": _this.offsetTop }
  }
   
  $(w).scroll(function() {
    // what the y position of the scroll is
    var scrollPos = e.scrollTop
    console.log(scrollPos)
    // compare to cached objects
    for (obj in pagesCache) {
      if (scrollPos >= pagesCache[obj].offset) {
        $(pagesCache[obj].node).addClass('page-fixed')
      } else {
        $(pagesCache[obj].node).removeClass('page-fixed')
      }
    }
  });  
});
              
            
!
999px

Console