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

              
                <section id="wrapper" class="colorOne">
  
  <header>
    Using Simple JS/jQuery and classes to get a cool transition effect on scroll.
    <h2>(On phone view in debug mode)</h2>
  </header>
  
  <article class="item">
    <h1>01</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin non varius nulla. Pellentesque sit amet sodales eros. Nam quis nibh vitae risus feugiat pulvinar vel eu est. Nam ex massa, rhoncus mattis est ac, iaculis vulputate nisl. Donec maximus nisi eu ipsum semper, eu euismod mi sodales. Nunc id felis sit amet sem faucibus placerat. Sed consectetur lectus metus, et ullamcorper nisi fermentum sit amet. Sed in volutpat magna, nec accumsan orci. Aenean turpis lectus, tincidunt nec diam et, condimentum scelerisque nisi. Aenean elementum neque eros, et interdum enim faucibus et. Cras eleifend interdum felis, non dignissim purus vulputate in. Suspendisse vel nunc dolor. Curabitur venenatis nisi non odio auctor, et malesuada odio tincidunt.</p>
  </article>
  
  <article class="item">
    <h1>02</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin non varius nulla. Pellentesque sit amet sodales eros. Nam quis nibh vitae risus feugiat pulvinar vel eu est. Nam ex massa, rhoncus mattis est ac, iaculis vulputate nisl. Donec maximus nisi eu ipsum semper, eu euismod mi sodales. Nunc id felis sit amet sem faucibus placerat. Sed consectetur lectus metus, et ullamcorper nisi fermentum sit amet. Sed in volutpat magna, nec accumsan orci. Aenean turpis lectus, tincidunt nec diam et, condimentum scelerisque nisi. Aenean elementum neque eros, et interdum enim faucibus et. Cras eleifend interdum felis, non dignissim purus vulputate in. Suspendisse vel nunc dolor. Curabitur venenatis nisi non odio auctor, et malesuada odio tincidunt.</p>
  </article>
  
  <article class="item">
     <h1>03</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin non varius nulla. Pellentesque sit amet sodales eros. Nam quis nibh vitae risus feugiat pulvinar vel eu est. Nam ex massa, rhoncus mattis est ac, iaculis vulputate nisl. Donec maximus nisi eu ipsum semper, eu euismod mi sodales. Nunc id felis sit amet sem faucibus placerat. Sed consectetur lectus metus, et ullamcorper nisi fermentum sit amet. Sed in volutpat magna, nec accumsan orci. Aenean turpis lectus, tincidunt nec diam et, condimentum scelerisque nisi. Aenean elementum neque eros, et interdum enim faucibus et. Cras eleifend interdum felis, non dignissim purus vulputate in. Suspendisse vel nunc dolor. Curabitur venenatis nisi non odio auctor, et malesuada odio tincidunt.</p>
  </article>
  
  <article class="item">
     <h1>04</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin non varius nulla. Pellentesque sit amet sodales eros. Nam quis nibh vitae risus feugiat pulvinar vel eu est. Nam ex massa, rhoncus mattis est ac, iaculis vulputate nisl. Donec maximus nisi eu ipsum semper, eu euismod mi sodales. Nunc id felis sit amet sem faucibus placerat. Sed consectetur lectus metus, et ullamcorper nisi fermentum sit amet. Sed in volutpat magna, nec accumsan orci. Aenean turpis lectus, tincidunt nec diam et, condimentum scelerisque nisi. Aenean elementum neque eros, et interdum enim faucibus et. Cras eleifend interdum felis, non dignissim purus vulputate in. Suspendisse vel nunc dolor. Curabitur venenatis nisi non odio auctor, et malesuada odio tincidunt.</p>
  </article>
  
</section>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Roboto:300,700);

#wrapper{
  width: 100%;
  height: 100%;
  font-family: 'Roboto', sans-serif;
  /*transition for the background color*/
  -webkit-transition: background-color 500ms;
   -moz-transition: background-color 700ms;
   -o-transition: background-color 700ms;
   transition: background-color 700ms;
}

/*color classes to be applied to "#wrapper" by the js*/
.colorOne{
  background-color: #BF3F3F;
}
.colorTwo{
  background-color: #59A57F;
}
.colorThree{
  background-color: black;
}
.colorFour{
  background-color: #7FBF3F;
}

/*layout styles not really relevant to this demo*/

header{
  width: 100%;
  color: white;
  background-color: #191919;
  text-align: center;
  padding: 1em 0 1em 0;
  margin-bottom: 100px;
}
h2{
  font-size: .7em;
  padding-top: .5em;
}

.item{
  width: 100%; 
  max-width: 600px;
  margin: 0 auto;
  height: 650px;
  padding: 0px 0 10px 0;
}

h1{
  color: white;
  display: inline-block;
  width: 32%;
  vertical-align: top;
  font-size: 10em;
  font-weight: 700;
}
p{
  width: 64%;
  display: inline-block;
  color: white;
  line-height: 170%;
  font-size: .9em;
  font-weight: 300;
}

@media screen and (max-width: 550px) {
  h1{
    display: block;
    width: 90%;
    margin-left: 3%;
  }
  p{
    display: block;
    width: 90%;
    margin-left: 3%;
  }
  header{
    margin-bottom: 30px;
  }
  
}


              
            
!

JS

              
                /*
this function will add different background color classes to "#wrapper" when the window is scrolled to a certain height. It will also remove the next color class so it reverts to the appropriate color when the user scrolls back up. Could be simplified, but this is easy to understand and alter.
*/

$(window).scroll(function() {
  if ($(this).scrollTop() <= 450) {
    $('#wrapper').addClass('colorOne')
      .removeClass('colorTwo');
  } else if ($(this).scrollTop() <= 1000) {
    $('#wrapper').addClass('colorTwo')
      .removeClass('colorThree');
  } else if ($(this).scrollTop() <= 1500) {
    $('#wrapper').addClass('colorThree')
      .removeClass('colorFour');
  } else if ($(this).scrollTop() <= 1850) {
    $('#wrapper').addClass('colorFour')
      .removeClass('colorFive');
  } else {
    $('#wrapper').addClass('colorOne')
  }
});
              
            
!
999px

Console