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 class="scroller">

  <section class="spacer">
    <h2>Spacer</h2>
  </section>
  
  
  <div class="trigger-wrap">
    <section class="main">

      <div class="text-container">          
        <div class="panel-text blue">Blue</div> 
        <div class="panel-text red">Red</div>   
        <div class="panel-text orange">Orange</div> 
        <div class="panel-text purple">Purple</div> 
      </div>

      <div class="image-container">
        <div class="panel-image blue"></div> 
        <div class="panel-image red"></div>
        <div class="panel-image orange"></div> 
        <div class="panel-image purple"></div> 
      </div>

    </section>
  </div>
  
  
  <section class="spacer">
    <h2>Spacer</h2>
  </section>

</div>
              
            
!

CSS

              
                * {
  margin: 0;
}

body {
  font-family: sans-serif;
  overflow: hidden;
}

.scroller {
  height: 100vh;
}



h2 {
  text-transform: uppercase;
  font-size: 6vh;
  color: #333;
}

section {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

section.spacer {
  background-color: #EEE;
}

section.main {
  background-color: #333;
}

section.main h2 {
  color: #EEE;
}



.text-container {
  position: relative;
  overflow: hidden;
  width: 30vw;
  margin-right: 5vw;
  height: 100%;
  //background: lightgrey;  
}

.panel-text {
  position: absolute;
  inset: 0;
  width: 100%;
  //height: 100%;
  height: max-content;
  
  font-size: 6vw;
  text-transform: uppercase;
  font-weight: 900;  
  
  display: flex;
  align-items: center;
  justify-content: center;
  
  //background-color: #666;  
  //background-color: #333;  
}

.panel-text.blue {
  color: blue;
}
.panel-text.red {
  color: red;
}
.panel-text.orange {
  color: orange;
}
.panel-text.purple {
  color: purple;
}



.image-container {
  position: relative;
  overflow: hidden;
  width: 30vw;
  margin-left: 5vw;
  height: 80%;
  //background: grey; 
}

.panel-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.panel-image.blue {
  background-color: blue;
}
.panel-image.red {
  background-color: red;
}
.panel-image.orange {
  background-color: orange;
}
.panel-image.purple {
  background-color: purple;
}
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);


const setScroller = document.querySelector('.scroller')


let smoothScrollBar = Scrollbar.init(setScroller, {
  damping: 0.1,
  delegateTo: document,
});

ScrollTrigger.scrollerProxy(setScroller, {
  scrollTop(value) {
    if (arguments.length) {
      smoothScrollBar.scrollTop = value;
    }
    return smoothScrollBar.scrollTop;
  }
});

smoothScrollBar.addListener(ScrollTrigger.update);





gsap.set(".panel-image", { zIndex: (i, target, targets) => targets.length - i });
gsap.set(".panel-text", { zIndex: (i, target, targets) => targets.length - i });

var images = gsap.utils.toArray('.panel-image:not(.purple)');
var texts = gsap.utils.toArray('.panel-text');





// Pinning ScrollTrigger

ScrollTrigger.create({

    trigger: "section.main",
    scroller: ".scroller",
    markers: true,
    pin: true,
    start: () => "top top",
    end: () => "+=" + ((images.length + 1) * window.innerHeight),
    invalidateOnRefresh: true

});





// Tweening ScrollTrigger's with wrapper as trigger

images.forEach((image, i) => {
  
  var tl = gsap.timeline({
    
    scrollTrigger: {
      trigger: ".trigger-wrap",
      scroller: ".scroller",
      start: () => "top top-=" + (window.innerHeight*(i + 0.5)),
      end: () => "+=" + window.innerHeight,
      scrub: true,
      toggleActions: "play none reverse none",
      invalidateOnRefresh: true    
    }
    
  })
  
  tl.fromTo(image, { height: () => "100%" }, { height: () => "0%" });  
  
});



texts.forEach((text, i) => {
  
  var tl = gsap.timeline({
    
    scrollTrigger: {
      trigger: ".trigger-wrap",
      scroller: ".scroller",
      start: () => "top top-=" + (window.innerHeight * (i - 0.5)),
      end: () => "+=" + (window.innerHeight * 2),
      scrub: true,
      toggleActions: "play none reverse none",
      invalidateOnRefresh: true    
    }
    
  })
  
  tl
    .to('body', { duration: 1 })
    .fromTo(text, { opacity: 0, y: () => window.innerHeight }, { duration: 0.25, opacity: 1, y: () => (window.innerHeight/2 - text.offsetHeight/2) }, 0.0)  
    .fromTo(text, { opacity: 1, y: () => (window.innerHeight/2 - text.offsetHeight/2) }, { duration: 0.25, opacity: 0, y: () => -text.offsetHeight , immediateRender: false }, 0.75)
  ;
  
})










// Only necessary to correct marker position - not needed in production

if (document.querySelector('.gsap-marker-scroller-start')) {    
  const markers = gsap.utils.toArray('[class *= "gsap-marker"]'); 
  smoothScrollBar.addListener(({ offset }) => {  
    gsap.set(markers, { marginTop: -offset.y })
  });
}
              
            
!
999px

Console