Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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="red-container">
    <div class="red-text text-1">
      <h1>HERE'S ONE</h1>
    </div>
    
      <div class="red-text text-2">
            <h1>WHAT ABOUT TWO?</h1>

  </div><div class="description panel blue">
  <div><h1>Layered pinning with infinite looping</h1>
    <p>Use pinning to layer panels on top of each other as you scroll.</p>
    <div class="scroll-down">Scroll down<div class="arrow"></div></div>
  </div>
</div>


<section class="panel red">
  <div class="red-scroller">
	 <div class="chapterWrapper">
        <div class="chapter chapter1">
<p>1. orem ipsum dolor sit amet, consectetur adipiscing elit. Morbi turpis velit, vestibulum in vulputate id</p>

        </div>

          <div class="chapter chapter2">
<p>2/ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi turpis velit, vestibulum in vulputate id</p>
</div>

  <div class="chapter chapter3">
  <p>3. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi turpis velit, vestibulum in vulputate id</p>

</div>
</div>
    </div>
    
  </div>
</section>
<section class="panel orange">
  <h1 class="s2-title"> panel orange </h1>
      <div class="chapter0">
<p>1. orem ipsum dolor sit amet, consectetur adipiscing elit. Morbi turpis velit, vestibulum in vulputate id</p>

        </div>
       
       </section>
<section class="panel purple">
  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmodtempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</section>
<section class="panel green">
	FOUR
</section>





<header>
   <a href="https://greensock.com/scrolltrigger">
     <img class="greensock-icon" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/scroll-trigger-logo-light.svg" width="200" height="64" />
  </a> 
</header>
              
            
!

CSS

              
                .red-scroller {
  height: 100vh;
}

.red-container {
  position: relative;
  z-index: 1;
  height: 100vh;
}

.red-text {
  position: absolute;
  
}

.text-2 {
  z-index: auto;
}
.text-1 {
  z-index: auto;
}

.purple {
  height: 100vh;
}

.panel {
  height: auto;
  min-height: 100vh;
}

.orange {
  display: flex;
  height: 100vh;
}



.chapterWrapper {
    position: relative;
    height: 100vh;
    margin: auto;
    width: 50%;



}

.chapter {
    z-index: 1;
    position: absolute;
    opacity: 0;
    height: 50vh;
   


}

.chapter0 {
    width: 100vw;
    background-color: white;
    height: 30vh;
    color: black;
    z-index:1;
}
.chapter1 {
    /* height: 100vh; */
    z-index: 1;
    background-color: purple;
    transform: translateY(0%);
    opacity: 1;


}

.chapter2 {
    /* height: 40vh; */
    z-index: auto;
    background-color: pink;
    transform: translateY(100%);



}

.chapter3 {
    /* height: 40vh; */
    z-index: auto;
    background-color: grey;
    transform: translateY(100%);


}




              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);
 

let panels = gsap.utils.toArray(".panel"),
    copy = panels[0].cloneNode(true);
panels[0].parentNode.appendChild(copy); // copy the first panel to the end (for seamless looping)

panels.forEach((panel, i) => {
  ScrollTrigger.create({
    trigger: panel,
    start: "bottom bottom", 
    pin: true, 
    pinSpacing: false 
  });
});


let maxScroll, snapValues;
let pageScrollTrigger = ScrollTrigger.create({ // snap whole page to the closest section
  // normally we'd just do snap: 1 / panels.length but we'll use a function-based value so that we can handle the very start and end values in a special way to prevent looping on the snap. Plus there are variable-height sections.
  snap: value => gsap.utils.snap(snapValues, value) 
});
function onResize() {
  maxScroll = ScrollTrigger.maxScroll(window);
  let totalHeight = 0,
      offset = 1.05 / maxScroll;
  // loop through each panel and figure out its height and convert that into an overall progress value
  snapValues = panels.map((panel, i) => (totalHeight += panel.offsetHeight) / maxScroll);
  snapValues.unshift(offset); // offset the start slightly to avoid infinite looping when snapping. Only make it go back to about 1px instead of 0. 
  snapValues[snapValues.length - 1] -= offset; // same for the end - snap to about 1px from the end to avoid infinite looping
  maxScroll -= 1;
}
onResize();
window.addEventListener("resize", onResize);
// make sure we use a non-passive event listener so that we can preventDefault() on the scroll if it's at the very top or bottom
window.addEventListener("scroll", e => {
  let scroll = pageScrollTrigger.scroll()
  if (scroll > maxScroll) {
    pageScrollTrigger.scroll(1);
    e.preventDefault();
  } else if (scroll < 1) {
    pageScrollTrigger.scroll(maxScroll - 1);
    e.preventDefault();
  }
}, {passive: false});


gsap.set(".chapter:not(.chapter1)", { zIndex: (i, target, targets) => targets.length - i });

var chapters = gsap.utils.toArray('.chapter:not(.chapter1)');


chapters.forEach(chapter => {
  var chaptl = gsap.timeline({
    defaults: {ease: "power3"},
    scrollTrigger: {
    //   scroller: ".section-2",
      trigger:".red",
      start: "top top",
    //   endTrigger:".section-2",
    end: () => "+=" + window.innerHeight,
      scrub: true,
      markers: true,
      pin: ".red",
      toggleActions: "play none reverse none",


    }

  })

//   .fromTo(chapter, {y: -500}, {y: 0}, 0)
//   .from(chapter.nextElementSibling, {scale: 0.8}, 0)
chaptl
.to(chapter, {y: "0%", opacity:1, duration: 0.33})
.to(chapter, {y: "100%", opacity:0, duration: 0.33}, 0.66)

;

// chaptl.to(chapter, {y: "100%", duration: 0.33});

// chaptl.to(chapter, {y: "-100%", duration: 0.33});

// chaptl.to(chapter, {y: "0%", duration: 0.33});

});


ScrollTrigger.create({

trigger: ".red",
// scroller: ".scroller",
scrub: true,
markers: true,
pin: true,
start: () => "top top",
end: () => "+=" + ((chapters.length + 1) * window.innerHeight),
invalidateOnRefresh: true,

});

              
            
!
999px

Console