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 id="app"></div>
              
            
!

CSS

              
                * {
	margin: 0;
	padding: 0;
	overflow-x: hidden;
}

.vertical-scroll {
	position: relative;
}

.sectionA,
.sectionB,
.sectionC,
.sectionD,
.sectionE,
.sectionF,.sectionG,.sectionH{
	height: 100vh;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 4rem;
}
.green{
	background:green;
}
.gray{
	background: gray;
}
.content-center {
	display: flex;
	align-items: center;
	justify-content: center;
}

.h-100vh {
	height: 100vh;
}

section {
	width: 100%;
}

.lightgreen {
	background: lightgreen;
}

.lightblue {
	background: lightblue;
}

.pink {
	background: pink;
}

.orange {
	background: orange;
}

.yellow {
	background: yellow;
}
.red{
	background: red;
}
.blue{
	background: blue;
}
.purple{
	background: purple;
}

.sectionC {
  height: 100vh;
  position: relative;
  display: flex;
  width: 200vw;
  display: flex;
  align-items: center;
  justify-content: center;
}
.horizontalSection {
  width: 100vw;
	height: 100vh;
}
              
            
!

JS

              
                const { useRef, useLayoutEffect } = React;
gsap.registerPlugin(ScrollTrigger);

const App = () => {
  const mainRef = useRef();
  const aRef = useRef();
  const bRef = useRef();
  const cRef = useRef();
  const dRef = useRef();
  const eRef = useRef();
  useLayoutEffect(() => {
    const handleScroll = () => {
      // eslint-disable-next-line no-unused-vars
      const { scrollY } = window;
      // eslint-disable-next-line no-unused-vars
      const sectionOffsets = {
        aRef: aRef?.current?.offsetTop || 0,
        bRef: bRef?.current?.offsetTop || 0,
        cRef: cRef?.current?.offsetTop || 0,
        dRef: dRef?.current?.offsetTop || 0,
        eRef: eRef?.current?.offsetTop || 0
      };
    };

    const gsapContext = gsap.context(() => {
      const horizontalScrollData =      gsap.utils.toArray(".horizontalSection");
      gsap.to(horizontalScrollData, {
        xPercent: -100 * (horizontalScrollData.length - 1),
        ease: "none",
        scrollTrigger: {
          trigger: cRef.current,
          scrub: 1,
          pin: true,
          snap: {
            snapTo: 1 / (horizontalScrollData.length - 1),
            duration: { min: 0.25, max: 0.75 },
            delay: 0.125,
            ease: "power1.inOut"
          },
          end: () => `+=${cRef?.current?.offsetWidth}`
        }
      });
      // gsap for A-C vertical scroll snap
      gsap.timeline({
        scrollTrigger: {
          trigger: ".first",
          start: "top top",
          endTrigger: ".sectionC",
          // markers: true,
          end: "bottom bottom",
          snap: {
            snapTo: 1 / 2,
            duration: { min: 0.25, max: 0.75 },
            delay: 0.125,
            ease: "power1.inOut"
          }
        }
      });

      // gsap for D,E snap vertical

      gsap.timeline({
        scrollTrigger: {
          trigger: ".sectionD",
          endTrigger: "sectionE",
          start: "top bottom+=1",
          end: "bottom bottom",
          snap: {
            snapTo: 1 / 2,
            duration: { min: 0.25, max: 0.75 },
            delay: 0.125,
            ease: "power1.inOut"
          }
        }
      });
    }, mainRef);
    window.addEventListener("scroll", handleScroll);

    return () => {
      gsapContext.revert();
      window.removeEventListener("scroll", handleScroll);
    };
  });
  return (
    <div ref={mainRef}>
      <section className="sectionA orange content-center first" ref={aRef}>
        section A
      </section>
      <section className="sectionB red content-center" ref={bRef}>
        section B
      </section>
      <section className="section sectionC" ref={cRef}>
        <div className="horizontalSection green flex items-center">
          Horizontal 1
        </div>
        <div className="horizontalSection yellow flex items-center">
          Horizontal 2
        </div>
      </section>
      <div className="section green sectionD" ref={dRef}>
        section D
      </div>
      <section className="sectionE blue content-center h-100vh" ref={eRef}>
        section E
      </section>
    </div>
  );
};

ReactDOM.render(<App />, document.getElementById("app"));

              
            
!
999px

Console