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 data-scroll-container>
  <section style="--backgroundColor: red; --textColor: #FFF;" data-scroll-section data-section-parallax>
  <div data-scroll-section-inner>
    RED
  </div>
  </section>
    <section style="--backgroundColor: green; --textColor: #FFF;" data-scroll-section data-section-parallax>
  <div data-scroll-section-inner>
    Green
  </div>
  </section>
  <section style="--backgroundColor: yellow; --textColor: #FFF;" data-scroll-section data-section-parallax>
  <div data-scroll-section-inner>
    Yellow
  </div>
  </section>
</div>
              
            
!

CSS

              
                section {
  height: 100vh;
  background-color: var(--backgroundColor);
  font-size: 15vw;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  color: var(--textColor);
}
              
            
!

JS

              
                const $locomotiveScrollContainer = document.querySelector('[data-scroll-container]');

gsap.registerPlugin(ScrollTrigger);
    document.body.style.overflow = 'hidden';

    const locomotiveScroll = new LocomotiveScroll({
      el: $locomotiveScrollContainer,
      smooth: true,
      lerp: 0.1
    });

    // tell ScrollTrigger to use these proxy methods for the smooth scroll container since Locomotive Scroll is hijacking things
    ScrollTrigger.scrollerProxy($locomotiveScrollContainer, {
      scrollTop(value) {
        return arguments.length ? locomotiveScroll.scrollTo(value, 0, 0) : locomotiveScroll.scroll.instance.scroll.y;
      },
      getBoundingClientRect() {
        return {top: 0, left: 0, width: window.innerWidth, height: window.innerHeight};
      },
      // LocomotiveScroll handles things completely differently on mobile devices - it doesn't even transform the container at all! So to get the correct
      // behavior and avoid jitters, we should pin things with position: fixed on mobile. We sense it by checking to see if there's a transform applied to the
      // container (the LocomotiveScroll-controlled element).
      pinType: $locomotiveScrollContainer.style.transform ? "transform" : "fixed"
    });


    // each time Locomotive Scroll updates, tell ScrollTrigger to update too (sync positioning)
    locomotiveScroll.on("scroll", ScrollTrigger.update);

    // each time the window updates, we should refresh ScrollTrigger and then update LocomotiveScroll.
    ScrollTrigger.addEventListener("refresh", () => locomotiveScroll.update());

    // after everything is set up, refresh() ScrollTrigger and update LocomotiveScroll because padding may have been added for pinning, etc.
    ScrollTrigger.refresh();

gsap.utils.toArray('[data-section-parallax] [data-scroll-section-inner]').forEach($sectionParallax => {
      ScrollTrigger.create({
        trigger: $sectionParallax,
        start: "top top",
        pin: true,
        pinSpacing: false,
        scroller: '[data-scroll-container]'
      });
    });
              
            
!
999px

Console