Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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="intro">
  <!--top panel with basketball-->
  <div class="caption">
    <h2>(Almost) Static Background</h2>
    <p>This section has a background that moves slightly slower than the user scrolls. This is achieved by changing the top position of the background for every pixel the page is scrolled.</p>
  </div>

</section>


<section id="second">
  <!--middle section with shoes-->
  <div class="shoe"></div>
<!-- this extra div becomes the additional floating shoe background layer-->
  <div class="caption">
    <h2>Multiple Backgrounds</h2>
    <p>The multiple backgrounds applied to this section are moved in a similar way to the first section -- every time the user scrolls down the page by a pixel, the positions of the backgrounds are changed.</p>
  </div>
</section>


<section id="third">
  <!--bottom section with shoes-->
  <div class="caption">
    <h2>What Happens When JavaScript is Disabled?</h2>
    <p>The user gets a slap! Actually, all that jQuery does is moves the backgrounds relative to the position of the scrollbar. Without it, the backgrounds simply stay put and the user would never know they are missing out on the awesome! CSS2 does a good
      enough job to still make the effect look cool.</p>
  </div>
</section>
              
            
!

CSS

              
                /*TYPE STYLING*/

body {
  font-family: Helvetica;
  font-size: 16px;
  line-height: 24px;
  color: white;
  background-color: black;
}

h2 {
  font-size: 32px;
  line-height: 30px;
  font-weight: bold;
  margin-bottom: 1em;
}

.caption {
  width: 30%;
}
/*LAYOUT STYLES*/

section {
  position: relative;
}

.caption {
  position: absolute;
}
/*NOTE here I'm using the "absolutely positioned children" inside "position relative parents" to place the text blocks in each section'*/

#intro .caption {
  top: 100px;
  left: 200px;
}

#second .caption {
  top: 150px;
  right: 100px;
}

#third .caption {
  bottom: 100px;
  left: 100px;
}
/*FINALLY, Add all the parallax images as position fixed backgrounds. These are controlled the javascript based on scroll*/

#intro {
  background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/1412/plax_firstBG.jpg) no-repeat fixed;
/* background-size:cover;*/
height: 600px;
}

#second {
  background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/1412/plax_secondBG.jpg) 50% 0 no-repeat fixed;
 height: 1300px;
  overflow: hidden;
}
.shoe {
  background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/1412/plax_trainers.png) 50% 0 no-repeat fixed;
  height: 1300px;

}

#third {
  background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/1412/plax_thirdBG.jpg) 50% 0 no-repeat fixed;
  height: 600px;
  padding-bottom: 300px;
}


/*
A simple and cleaned-up demo of Ian Lunn's "NBW" Nike Better World parallax plugin for jQuery
Plugin: jQuery Parallax
Version 1.1.3
Author: Ian Lunn
Twitter: @IanLunn
Author URL: https://www.ianlunn.co.uk/
Plugin URL: https://www.ianlunn.co.uk/plugins/jquery-parallax/

License: http://creativecommons.org/licenses/by-sa/3.0/ (Attribution Share Alike). Please attribute work to Ian Lunn simply by leaving these comments in the source code or if you'd prefer, place a link on your website to https://www.ianlunn.co.uk/.
*/
              
            
!

JS

              
                //.parallax(xPosition, speedFactor, outerHeight) options:
//xPosition - Horizontal position of the element
//inertia - speed to move relative to vertical scroll. Example: 0.1 is one tenth the speed of scrolling, 2 is twice the speed of scrolling
$('#intro').parallax("50%", 0.1);
$('#second').parallax("50%", 0.1);
$('.shoe').parallax("50%", 0.4);
$('#third').parallax("50%", 0.3);

//NOTE: Not used in this demo by available in the plugin - outerHeight (true/false) - Whether or not jQuery should use it's outerHeight option to determine when a section is in the viewport
              
            
!
999px

Console