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

              
                // available colors: primary | secondary | white | ghost
- var navStartColor = 'ghost' 
- var navIntoColor = 'secondary'

// available sizes: xl | lg | md | sm
- var navStartSize = 'xl'
- var navIntoSize = 'md'


// the bootstrap navbar
nav.navbar.navbar-fixed-top(
  class=(`navbar--color--${navStartColor}`)
  class=(`navbar--size--${navStartSize}`)
  data-startColor=(`navbar--color--${navStartColor}`)
  data-startSize=(`navbar--size--${navStartSize}`)
  data-intoColor=(`navbar--color--${navIntoColor}`)
  data-intoSize=(`navbar--size--${navIntoSize}`)
)

  .container
    .navbar-header
      button.navbar-toggle.collapsed(
        type='button', 
        data-toggle='collapse', 
        data-target='#mobileNav', 
        aria-expanded='false'
      )
        span.sr-only Toggle navigation
        span.icon-bar
        span.icon-bar
        span.icon-bar
      a.navbar-brand(href='#') ElasticNav.

    #mobileNav.collapse.navbar-collapse
     p.navbar-right.navbar-text Scroll down to trigger the nav transition.

// some content to allow scrolling :)
.hero
  .overlay
.main-content
  
  - var i = 0
  while i < 9
    section
      .container
        h2 Your journey starts here.
        p  This is it. You've made it so far. There is no going back.
        p Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dicta iste molestias vel commodi, quae quaerat ex numquam. Consectetur corporis explicabo, qui labore, repellat dignissimos illo molestias maxime nisi a consequuntur?
        p  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit fuga autem dolore, ex nobis, iste quasi, asperiores esse repellendus tempore, obcaecati numquam minima maxime! Laboriosam, ut ipsam magnam corporis aut.
        h3 Get lost and find yourself.
        p  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sequi placeat dolor molestias facere veritatis culpa amet fugiat debitis dolorem qui quidem consequuntur mollitia, nesciunt pariatur voluptatum! Dolor accusamus labore, sequi.

        - i++
              
            
!

CSS

              
                // variables
        $primary = #37ca7e
      $secondary = #43a6dd
$transitionSpeed = 0.4s

// Lato font
@import url(https://fonts.googleapis.com/css?family=Lato:400,700,900);

// basic styles
body
  font-family 'Lato', Arial, sans-serif
  color #6b6b6b
  font-size 17px
  line-height 1.6
    
.hero
  position relative
  height 60vh
  z-index -2
  background url('https://unsplash.it/2000/800?image=563') center top / cover no-repeat
  
.overlay
  position absolute
  z-index -1
  top 0
  left 0
  height 100%
  width 100%
  background rgba(#000, 0.6)

.main-content
  background #f2f2f2

section
  background white
  padding 4rem 0 7rem
  
  // zebra striping the sections
  &:nth-child(even)
    background darken(white, 4)

h2, h3
  padding 2rem 0 .75rem
  font-weight 700
  color #4b4b4b

  
/* ===================================== */
/* ===== THE INTERESTING STUFF NOW ===== */
/* ===================================== */

.navbar
  border none
  transition $transitionSpeed
  
  &-brand
    font-size 2.25rem
    font-weight 900
    color #4b4b4b

  /* --- navbar sizes --- */  
  &--size
    
    &--xl
      padding 4rem 0
      
    &--lg
      padding 2rem 0
    
    &--md
      padding 1rem 0
      
    &--sm
      padding 0
      
  
  /* --- navbar colors --- */
  &--color
    
    &--white
      background white
      
    &--primary
      background $primary
      
    &--secondary
      background $secondary
      
    &--ghost
      background rgba(0,0,0,0.2)
      
      .navbar-brand,
      .navbar-text,
      a 
        color white        
      
      

              
            
!

JS

              
                // grabbing the class names from the data attributes
const navBar = $('.navbar'),
      data = navBar.data();

// booleans used to tame the scroll event listening a little..
let scrolling = false,
    scrolledPast = false;

// transition Into
function switchInto() {
  // update `scrolledPast` bool
  scrolledPast = true;
  // add/remove CSS classes
  navBar.removeClass(data.startcolor);
  navBar.removeClass(data.startsize);
  navBar.addClass(data.intocolor);
  navBar.addClass(data.intosize);
  console.log('into transition triggered!')
};

// transition Start
function switchStart() {
  // update `scrolledPast` bool
  scrolledPast = false;
  // add/remove CSS classes
  navBar.addClass(data.startcolor);
  navBar.addClass(data.startsize);
  navBar.removeClass(data.intocolor);
  navBar.removeClass(data.intosize);
  console.log('start transition triggered!')
}

// set `scrolling` to true when user scrolls
$(window).scroll(() => scrolling = true);

setInterval(() => {
  // when `scrolling` becomes true... 
  if(scrolling) {      
    // set it back to false
    scrolling = false;
    // check scroll position
    if ($(window).scrollTop() > 100) {
      // user has scrolled > 100px from top since last check
      if ( !scrolledPast ) {
        switchInto(); 
      }
    } else {
      // user has scrolled back <= 100px from top since last check
      if ( scrolledPast ) {
        switchStart();
      }
    }
  }
// take a breath.. hold event listener from firing for 100ms
}, 100);
              
            
!
999px

Console