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="container">
  <div class="description panel blue">
    <div><h1>"labelsDirectional" snapping sections</h1>
      <p>Scroll vertically to scrub the horizontal animation. It snaps to the sections based on which direction you're scrolling whereas the typical snap: "labels" would require you to drag past halfway to snap to the next section.</p>
      <div class="scroll-down">Scroll down<div class="arrow"></div></div>
    </div>
  </div>


  <section class="panel red">
    ONE
  </section>
  <section class="panel orange">
    TWO
  </section>
  <section class="panel purple">
    THREE
  </section>
  <section class="panel green">
    FOUR
  </section>
  <section class="panel gray">
    FIVE
  </section>

</div>



<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

              
                .container {
  width: 600%;
  height: 100%;
  display: flex;
  flex-wrap: nowrap;
}

              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

let sections = gsap.utils.toArray(".panel"),
    count = sections.length - 1,
    duration = 1,
    tl = gsap.timeline({
      scrollTrigger: {
        trigger: ".container",
        pin: true,
        scrub: 1,
        snap: "labelsDirectional",
        end: () => "+=" + document.querySelector(".container").offsetWidth
      }
    });

// add a label at each section
sections.forEach((section, i) => tl.add("label" + i, i * (duration / count)));

tl.to(sections, {
  xPercent: -100 * count,
  duration: duration,
  ease: "none"
});


              
            
!
999px

Console