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

              
                <header class="parallax-wrapper">
  <div class="parallax">
    <h1>This header has parallax effect</h1>
  </div>
</header>
<main>
  <p>Because vanilla JS is awesome and nobody should have to import a whole library when you only need to write 6 lines of code. Voilà.</p>
</main>
              
            
!

CSS

              
                .parallax-wrapper {
  overflow-y: hidden;
}

.parallax {
  background-image: url('https://placeimg.com/1000/400/tech');
  background-size: cover;
  background-position: center;
  height: 250px;
}



/* Only for the pen */
html, body {
  margin: 0;
  min-height: 100%;
  font-family: sans-serif;
}

main {
  min-height: 500px;
  background-color: #2b2d42;
}

.parallax {
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

h1, p {
  margin: 0;
  color: #fff;
}

p {
  font-weight: 500;
  font-size: 1.2em;
  max-width: 600px;
  margin: 0 auto;
  text-align: center;
  line-height: 1.6;
  padding-top: 80px;
}
              
            
!

JS

              
                // Parallax effect
// Adapted from @ilonacodes article ->  https://link.medium.com/7fFiON6Q1X

// Update : added throttle to increase performance
window.addEventListener('scroll', throttle(parallax, 14));

function throttle(fn, wait) {
  var time = Date.now();
  return function() {
    if ((time + wait - Date.now()) < 0) {
      fn();
      time = Date.now();
    }
  }
};

function parallax() {
  var scrolled = window.pageYOffset;
  var parallax = document.querySelector(".parallax");
  // You can adjust the 0.4 to change the speed
	var coords = (scrolled * .4) + 'px'
  parallax.style.transform = 'translateY(' + coords + ')';
};
              
            
!
999px

Console