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

              
                h1 Parallax Sync Scrolling
p When you scroll to the bottom, each column's bottom margin will be aligned, despite having different heights. 
.container
  .blue.column
  .red.column
  .green.column
  
// three columns of different sizes scroll at different rates to sync their top and bottom borders.
              
            
!

CSS

              
                @mixin bg($color) {
  $light: darken($color, 12%);
  $dark: darken($color, 16%);
  background: repeating-linear-gradient(-45deg,
    $light,
    $light 10px,
    $dark 10px,
    $dark 20px
  );
}

body {
  margin: 0;
  padding: 0;
  background: repeating-linear-gradient(-45deg, darken(white, 4%), darken(white, 4%) 10px, darken(white, 6%) 10px, darken(white, 6%) 20px);
  font-family: monospace;
}

h1, p {
  text-align: center;
}

.container {
  display: flex;
  flex-direction: row;
  width: 100%;
  margin-bottom: 80px;
}

.column {
  flex: 1 1 auto;
  height: 100%;
  padding: 20px;
  color: #f0f0f0;
  text-align: center;
  font-size: 24px;
  overflow: hidden;
  &.blue {
    height: 400vh;
    @include bg(dodgerblue);
  }
  &.red {
    height: 770vh;
    @include bg(firebrick);
  }
  &.green {
    height: 620vh;
    @include bg(forestgreen);
  }
}
              
            
!

JS

              
                function parallaxSync(selector){
  
  // get selected elements and sort descending by height
  const elements = [...document.querySelectorAll(selector)];
  const descHeight = elements.sort((a,b) => b.getBoundingClientRect().height - a.getBoundingClientRect().height);
  
  // anchor, the tallest element, will scroll normally
  // links, all other elements, will scroll slower
  const [ anchor, ...links ] = descHeight;
  
  // this function's css transforms leverage position and top rules
  links.forEach(el => {
    Object.assign(el.style, {
      position: 'sticky',
      top: 0,
    })
  })
  
  // add window scroll listener
  window.addEventListener('scroll', e => {
    
    const anchorRect = anchor.getBoundingClientRect();
    
    // if anchor top is above viewport, apply parallax sync
    if (anchorRect.height > window.innerHeight && anchorRect.top < 0){
      
      // the ratio of pixels that the client is below the anchor's top
      // will be used to calculate the offset of every link's top
      const ratio = anchorRect.top / anchorRect.height;
      
      // iterate each link that is smaller than the anchor
      links.forEach(link => {
        const linkRect = link.getBoundingClientRect();
        
        // only apply parallax if the height is greater than the viewport
        // and the link's bottom is below the viewport bottom
        if (linkRect.height > window.innerHeight && window.innerHeight < linkRect.bottom){
          
          // apply ratio to the link height - viewport height,
          // matching the link's bottom to anchor's bottom
          const diff = linkRect.height - window.innerHeight;
          const offset = ratio * diff;
          
          // apply the css transform which will be a negative px value
          link.style.top = `${offset}px`;
        }
      })
    }
  });
}

parallaxSync('.column');

[...document.querySelectorAll('.column')].forEach(elem => {
  elem.innerHTML = `
    <h1>1.</h1>
<p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Volutpat consequat mauris nunc congue nisi vitae suscipit. Maecenas accumsan lacus vel facilisis volutpat est velit egestas dui. Ante in nibh mauris cursus. Scelerisque fermentum dui faucibus in ornare quam. Velit sed ullamcorper morbi tincidunt ornare. Arcu cursus vitae congue mauris rhoncus aenean. Tincidunt id aliquet risus feugiat. Sit amet volutpat consequat mauris nunc congue nisi. Adipiscing elit pellentesque habitant morbi tristique senectus et netus et. Vitae tempus quam pellentesque nec nam aliquam sem. In fermentum posuere urna nec tincidunt praesent semper feugiat. Turpis nunc eget lorem dolor sed.
</p>
<h1>2.</h1>
<p>
Lacinia at quis risus sed vulputate. Mi quis hendrerit dolor magna eget est lorem ipsum. In aliquam sem fringilla ut morbi tincidunt. Metus aliquam eleifend mi in nulla posuere sollicitudin aliquam. Semper auctor neque vitae tempus. Elit sed vulputate mi sit amet mauris commodo. Tristique nulla aliquet enim tortor. Habitasse platea dictumst vestibulum rhoncus est. Ac turpis egestas sed tempus urna et pharetra. Mollis nunc sed id semper risus in hendrerit gravida.
</p>
<h1>3.</h1>
<p>
Vulputate ut pharetra sit amet aliquam id diam. In fermentum posuere urna nec tincidunt praesent semper feugiat. Aliquam vestibulum morbi blandit cursus risus. Diam quam nulla porttitor massa. Elit sed vulputate mi sit amet. Quam elementum pulvinar etiam non quam lacus suspendisse faucibus. In nisl nisi scelerisque eu. Tellus mauris a diam maecenas sed. Egestas dui id ornare arcu odio ut sem. Vivamus arcu felis bibendum ut tristique et egestas. Mattis nunc sed blandit libero volutpat sed cras ornare arcu. Mauris vitae ultricies leo integer malesuada nunc. Lobortis elementum nibh tellus molestie nunc non blandit massa enim. Euismod quis viverra nibh cras pulvinar mattis nunc sed. Felis bibendum ut tristique et. Faucibus et molestie ac feugiat sed lectus.
</p>
<h1>4.</h1>
<p>
Aliquam vestibulum morbi blandit cursus risus at. A arcu cursus vitae congue mauris rhoncus. Sit amet consectetur adipiscing elit. Egestas purus viverra accumsan in nisl nisi scelerisque. Viverra mauris in aliquam sem fringilla. Cursus eget nunc scelerisque viverra mauris in. Eu mi bibendum neque egestas congue. Diam volutpat commodo sed egestas egestas fringilla. Habitasse platea dictumst vestibulum rhoncus est pellentesque elit ullamcorper. Dolor sit amet consectetur adipiscing elit pellentesque habitant. Volutpat blandit aliquam etiam erat velit scelerisque in.
</p>
<h1>5.</h1>
<p>
Adipiscing bibendum est ultricies integer quis auctor. Fringilla phasellus faucibus scelerisque eleifend. At ultrices mi tempus imperdiet. Malesuada fames ac turpis egestas. In hac habitasse platea dictumst vestibulum rhoncus est pellentesque. Gravida cum sociis natoque penatibus et magnis. Rhoncus est pellentesque elit ullamcorper dignissim cras. Volutpat commodo sed egestas egestas fringilla phasellus faucibus scelerisque. Viverra adipiscing at in tellus integer feugiat. Iaculis at erat pellentesque adipiscing commodo elit at imperdiet dui. Ut eu sem integer vitae justo eget magna. Dui vivamus arcu felis bibendum ut tristique. Donec et odio pellentesque diam volutpat. Eget nulla facilisi etiam dignissim. Donec et odio pellentesque diam volutpat commodo sed. Ornare lectus sit amet est placerat in. Ullamcorper malesuada proin libero nunc consequat interdum. Mauris in aliquam sem fringilla.
</p>
<h1>6.</h1>
<p>
Ullamcorper a lacus vestibulum sed arcu non. Eleifend quam adipiscing vitae proin sagittis. Dui accumsan sit amet nulla facilisi morbi tempus iaculis urna. Feugiat nibh sed pulvinar proin. Nibh tellus molestie nunc non blandit massa. Urna molestie at elementum eu facilisis sed odio. Dictum sit amet justo donec enim. Ipsum faucibus vitae aliquet nec. In pellentesque massa placerat duis ultricies. Orci porta non pulvinar neque laoreet suspendisse interdum. Est ultricies integer quis auctor elit sed vulputate mi sit. Ut consequat semper viverra nam libero. Tellus integer feugiat scelerisque varius morbi. Lobortis elementum nibh tellus molestie nunc. Dui ut ornare lectus sit amet est placerat. Habitasse platea dictumst vestibulum rhoncus est pellentesque. Nunc sed augue lacus viverra. Dignissim diam quis enim lobortis. Sit amet nulla facilisi morbi tempus iaculis urna.
</p>
  `
})
              
            
!
999px

Console