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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
              
            
!

CSS

              
                body {
  margin: 0;
}

section {  
  height: 100vh;  
}

section:nth-of-type(odd) {
  background: gainsboro
}
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

ScrollTrigger.config({ limitCallbacks: true });

const sections = gsap.utils.toArray("section");

// this scrolling object just allows us to conveniently call scrolling.enable(), scrolling.disable(), and check if scrolling.enabled is true.
// some browsers (like iOS Safari) handle scrolling on a separate thread and can cause things to get out of sync (jitter/jumpy), so when we're animating the scroll position, force an update of GSAP tweens when there's a scroll event in order to maintain synchronization)
const scrolling = {
  enabled: true,
  events: "scroll,wheel,touchmove,pointermove".split(","),
  prevent: (e) => e.preventDefault(),
  disable() {
    if (scrolling.enabled) {
      scrolling.enabled = false;
      window.addEventListener("scroll", gsap.ticker.tick, { passive: true });
      scrolling.events.forEach((e, i) =>
        (i ? document : window).addEventListener(e, scrolling.prevent, {
          passive: false
        })
      );
    }
  },
  enable() {
    if (!scrolling.enabled) {
      scrolling.enabled = true;
      window.removeEventListener("scroll", gsap.ticker.tick);
      scrolling.events.forEach((e, i) =>
        (i ? document : window).removeEventListener(e, scrolling.prevent)
      );
    }
  }
};

function goToSection(section, anim, i) {
  console.log(scrolling.enabled);

  if (scrolling.enabled) {
    // skip if a scroll tween is in progress
    scrolling.disable();

    gsap.to(window, {
      scrollTo: { y: section, autoKill: false },
      onComplete: scrolling.enable,
      duration: 1
    });

    anim && anim.restart();
  }

  console.log(section);
}

sections.forEach((section, i) => {
  ScrollTrigger.create({
    trigger: section,
    start: "top bottom-=1",
    end: "bottom top+=1",
    onEnter: () => goToSection(section),
    onEnterBack: () => goToSection(section)
  });
});

              
            
!
999px

Console