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

              
                <div class="container">
  <header class="page-header">
    <h1>Affix.js - Fixed <b>navbar</b> by scrolling the page with <b>Bootstrap</b></h1>
    <h2><small>Go down, Go down!</small></h2>
  </header>
</div>

<nav id="navbar-main" class="navbar navbar-inverse">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Project name</a>
    </div>
    <div id="navbar" class="collapse navbar-collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#about">About</a></li>
        <li><a href="#contact">Contact</a></li>
      </ul>
    </div>
    <!--/.nav-collapse -->
  </div>
</nav>

<main class="container">
  <p class="lead">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Id voluptatum sequi sunt asperiores eius, qui saepe tempore aliquam debitis distinctio officia optio unde perferendis fugiat sint quia consequuntur, placeat sed!</p>
  <p class="lead">Go down, Go down!</p>
  <p class="lead">Go down, Go down!</p>
  <p class="lead">Go down, Go down!</p>
  <p class="lead">Go down, Go down!</p>
  <p class="lead">Go down, Go down!</p>
  <p class="lead">Go down, Go down!</p>
  <p class="lead">Go down, Go down!</p>
  <p class="lead">Go down, Go down!</p>
  <p class="lead">Go down, Go down!</p>
  <p class="lead">Go down, Go down!</p>
  <p class="lead">Go down, Go down!</p>
  <p class="lead">Go down, Go down!</p>
  <p class="lead">Go down, Go down!</p>
  <p class="lead">Go down, Go down!</p>
  <p class="lead">Go down, Go down!</p>
</main>

<footer id="footer" class="footer">
  <p class="text-center"><br>This is my big footer, only test. :)</p>
</footer>
              
            
!

CSS

              
                #navbar-main {
  /* Added `.affix-top` class css when the element is top */
  &.affixed-top {
    background: black;
  }
  /* Added `.affix` class css when the element is >= 170px (Look: line 8 html) */
  &.affix {
    background: gray;
    top: 0;
    left: 0;
    right: 0;
  }
  /* Added `.affix-bottom` class css when the element is footer */
  &.affix-bottom {
    background: red; 
  }
}

/* Not important */
.footer {
  background: #eee;
  height: 1000px;
}
              
            
!

JS

              
                var affixElement = '#navbar-main';

$(affixElement).affix({
  offset: {
    // Distance of between element and top page
    top: function () {
      return (this.top = $(affixElement).offset().top)
    },
    // when start #footer 
    bottom: function () { 
      return (this.bottom = $('#footer').outerHeight(true))
    }
  }
});
              
            
!
999px

Console