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

              
                <div id="custom-scroll-container">
  <div class="placeholder">
    placeholder content
  </div>
  
  <div class="scrolltrigger-section">
    <div class="scrolltrigger-container" data-module-stackedslides>
      <div class="slide" data-slide style="background-color:pink;z-index:4">
        A one
      </div>
      <div class="slide" data-slide style="background-color:purple;z-index:3">
        A two
      </div>
      <div class="slide" data-slide style="background-color:cyan;z-index:2">
        A three
      </div>
      <div class="slide" data-slide style="background-color:green;z-index:1">
        A four
      </div>
    </div>
  </div>
  
  <div class="placeholder">
    placeholder content
  </div>
  
  <div class="scrolltrigger-section">
    <div class="scrolltrigger-container" data-module-stackedslides>
      <div class="slide" data-slide style="background-color:pink;z-index:6">
        B one
      </div>
      <div class="slide" data-slide style="background-color:purple;z-index:5">
        B two
      </div>
      <div class="slide" data-slide style="background-color:cyan;z-index:4">
        B three
      </div>
      <div class="slide" data-slide style="background-color:green;z-index:3">
        B four
      </div>
      <div class="slide" data-slide style="background-color:yellow;z-index:2">
        B five
      </div>
      <div class="slide" data-slide style="background-color:magenta;z-index:1">
        B six
      </div>
    </div>
  </div>
  
  <div class="placeholder">
    placeholder content
  </div>
</div>
              
            
!

CSS

              
                *,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100vh;
  margin: 0;
  overflow: hidden;
  padding: 0;
}

body {
  font-family: sans-serif;
}

// this custom scroll container is obviously not necessary in this demo, but is used in my larger project so I carried it over just to be safe in terms of the scrolltrigger setup 
#custom-scroll-container {
  height: 100vh;
	overflow-x: hidden;
	overflow-y: scroll;
}

.placeholder {
  align-items: center;
  background-color: #ddd;
  display: flex;
  height: 100vh;
  justify-content: center;
}

.scrolltrigger-container {
  height: 100vh;
  overflow: hidden;
  position: absolute;
  width: 100%;
}

.scrolltrigger-section {
  position: relative;
  
  .pin-spacer {
    position: relative !important;
  }
}

.slide {
  align-items: center;
  display: flex;
  font-size: 3em;
  font-weight: 700;
  height: 100vh;
  justify-content: center;
  position: absolute;
  width: 100%;
}
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

ScrollTrigger.defaults({ scroller: "#custom-scroll-container" });

let stacked_slides_modules = document.querySelectorAll('[data-module-stackedslides]');

stacked_slides_modules.forEach((module) => {
	let slides = module.querySelectorAll('[data-slide]:not(:last-child)');
	let end_spacing = 100 * slides.length;
	
	slides.forEach((slide) => {
		gsap.to(slide, {
			ease: "none",
			scrollTrigger: {
				end: "+=" + end_spacing + "%",
				pin: true,
				scrub: true,
				start: "top top",
				trigger: module
			},
			stagger: 0.5,
			yPercent: -100
		});
	});
});
              
            
!
999px

Console