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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

HTML

              
                <!-- header with progress container -->
<div id="heading">
  <h1>Progress Bar</h1>
  <div id="scroll_container">
    <div id="horizontal_scroll"></div>
  </div>
</div>

<!-- content -->
<div id="content">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis interdum orci. Nullam posuere massa neque, ut viverra ex sollicitudin quis. Nullam condimentum iaculis arcu, a ultrices quam lobortis id. Suspendisse nulla purus, interdum nec mattis ut, porttitor malesuada dolor. Quisque mattis, felis eget consequat molestie, purus diam laoreet nisi, ut scelerisque magna ligula tempus sapien. Morbi tincidunt, tortor sit amet iaculis consectetur, sem lectus egestas massa, non sodales sem arcu vel arcu. Ut nec ligula nibh. Mauris in commodo turpis. Vivamus vitae vestibulum nibh. Nullam mollis hendrerit sapien, id cursus enim fermentum in. Donec pellentesque, arcu id sodales pellentesque, odio ante tempus augue, ut fringilla ante urna vel metus. Praesent consequat massa dapibus, ullamcorper erat sit amet, mollis risus. Donec id elit tincidunt, eleifend diam et, molestie tellus.</p>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis interdum orci. Nullam posuere massa neque, ut viverra ex sollicitudin quis. Nullam condimentum iaculis arcu, a ultrices quam lobortis id. Suspendisse nulla purus, interdum nec mattis ut, porttitor malesuada dolor. Quisque mattis, felis eget consequat molestie, purus diam laoreet nisi, ut scelerisque magna ligula tempus sapien. Morbi tincidunt, tortor sit amet iaculis consectetur, sem lectus egestas massa, non sodales sem arcu vel arcu. Ut nec ligula nibh. Mauris in commodo turpis. Vivamus vitae vestibulum nibh. Nullam mollis hendrerit sapien, id cursus enim fermentum in. Donec pellentesque, arcu id sodales pellentesque, odio ante tempus augue, ut fringilla ante urna vel metus. Praesent consequat massa dapibus, ullamcorper erat sit amet, mollis risus. Donec id elit tincidunt, eleifend diam et, molestie tellus.</p>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis interdum orci. Nullam posuere massa neque, ut viverra ex sollicitudin quis. Nullam condimentum iaculis arcu, a ultrices quam lobortis id. Suspendisse nulla purus, interdum nec mattis ut, porttitor malesuada dolor. Quisque mattis, felis eget consequat molestie, purus diam laoreet nisi, ut scelerisque magna ligula tempus sapien. Morbi tincidunt, tortor sit amet iaculis consectetur, sem lectus egestas massa, non sodales sem arcu vel arcu. Ut nec ligula nibh. Mauris in commodo turpis. Vivamus vitae vestibulum nibh. Nullam mollis hendrerit sapien, id cursus enim fermentum in. Donec pellentesque, arcu id sodales pellentesque, odio ante tempus augue, ut fringilla ante urna vel metus. Praesent consequat massa dapibus, ullamcorper erat sit amet, mollis risus. Donec id elit tincidunt, eleifend diam et, molestie tellus.</p>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis interdum orci. Nullam posuere massa neque, ut viverra ex sollicitudin quis. Nullam condimentum iaculis arcu, a ultrices quam lobortis id. Suspendisse nulla purus, interdum nec mattis ut, porttitor malesuada dolor. Quisque mattis, felis eget consequat molestie, purus diam laoreet nisi, ut scelerisque magna ligula tempus sapien. Morbi tincidunt, tortor sit amet iaculis consectetur, sem lectus egestas massa, non sodales sem arcu vel arcu. Ut nec ligula nibh. Mauris in commodo turpis. Vivamus vitae vestibulum nibh. Nullam mollis hendrerit sapien, id cursus enim fermentum in. Donec pellentesque, arcu id sodales pellentesque, odio ante tempus augue, ut fringilla ante urna vel metus. Praesent consequat massa dapibus, ullamcorper erat sit amet, mollis risus. Donec id elit tincidunt, eleifend diam et, molestie tellus.</p>
</div>
              
            
!

CSS

              
                /* Google font */
@import url('https://fonts.googleapis.com/css?family=Open+Sans');

/* styling heading which is fixed on top */
#heading {
  position: fixed;
  top: 0;
  z-index: 1;
  width: 100%;
  text-align: center;
  background-color: #efefef;
  font-family: 'Open Sans', sans-serif;
}

/* styling container of progress bar */
#scroll_container {
  background-color: #ababab;
}

/* styling progress bar */
#horizontal_scroll {
  width: 0%;
  height: 7px;
  background-color: green;
}

/* styling content */
#content {
  margin-top: 150px;
  font-family: 'Open Sans', sans-serif;
}
              
            
!

JS

              
                /* call function on window scroll */
window.onscroll = function(){
  
  /* height scrolled from top */
  var scrolled_top = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  
  /* total scrollable height */
  var to_scroll = (document.documentElement.scrollHeight || document.body.scrollHeight) - (document.documentElement.clientHeight || document.body.clientHeight || window.innerHeight) 
  
  /* percentage of height scrolled */
  var horizontal_width = (scrolled_top/to_scroll)*100;
  
  /* assigning calculated width to progress bar */
  document.getElementById('horizontal_scroll').style.width = horizontal_width + '%';
}
              
            
!
999px

Console