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

CSS

              
                video,
img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.slides {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.slide {
  position: absolute;
  top: 0;
  width: 100%;
  height: 100vh;
  clip-path: polygon(0 100%, 100% 100%, 100% 100%, 0 100%);

  &:first-child {
    clip-path: polygon(0% 100%, 100% 100%, 100% 0%, 0% 0%);
  }

  a {
    position: relative;
    display: grid;
    height: 100vh;
    text-decoration: none;
  }
}

.outer,
.inner {
  width: 100%;
  height: 100%;
  overflow-y: hidden;
}

.container {
  display: grid;
  position: relative;
  height: 100vh;
  background-color: orange;
}

.slides,
.nav,
.line,
.bg {
  grid-area: 1 / 1;
}

.bg {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

.nav {
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-self: center;
  justify-self: flex-start;
  list-style-type: none;

  > li {
    button {
      display: inline-flex;
      align-items: center;
      cursor: pointer;
    }

    svg {
      width: 35px;
      margin-right: 12px;
      color: #fff;
      display: none;
    }

    h2 {
      color: blue;
      text-align: start;
    }

    &.is-active {
      svg {
        display: block;
      }
    }
  }
}

.line {
  width: 100%;
  max-width: 800px;
  height: 8px;
  margin: 0 0 10px 0;
  position: relative;
  top: 0;
  z-index: 1;
  display: inline-block;
  background-color: chocolate;
}

              
            
!

JS

              
                console.clear();

const { useEffect, useState, useRef } = React;

gsap.registerPlugin(ScrollToPlugin, ScrollTrigger, GSDevTools);

const sliderArr = [
  {
    id: 1,
    href: "/",
    src:
      "https://images.unsplash.com/photo-1526409049865-5b0b188372f1?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1632&q=50",
    navTitle: "Slide 1"
  },
  {
    id: 2,
    href: "/",
    src:
      "https://images.unsplash.com/photo-1425913397330-cf8af2ff40a1?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1074&q=50",
    navTitle: "Slide 2"
  },
  {
    id: 3,
    href: "/",
    src:
      "https://images.unsplash.com/photo-1551986782-d0169b3f8fa7?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=688&q=50",
    navTitle: "Slide 3"
  },
  {
    id: 4,
    href: "/",
    src:
      "https://images.unsplash.com/photo-1608478497783-158b45d36042?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=50",
    navTitle: "Slide 4"
  }
];

function App() {
  const containerRef = useRef(null);
  const slidesWrapperRef = useRef(null);
  const slides = useRef([]);
  const navItems = useRef([]);
  const bg = useRef([]);
  const slidesTl = useRef();
  const [ctx] = useState(gsap.context(() => {}, containerRef));
  const [activeNavItem, setActiveNavItem] = useState(0);

  useEffect(() => {
    ctx.add(() => {
      // const slides = gsap.utils.toArray(".slide");

      slidesTl.current = gsap.timeline({
        id: "hero-animation",
        defaults: {
          ease: "none",
          duration: 1
        },
        scrollTrigger: {
          trigger: containerRef.current,
          pin: true, // locked the slidesWrapperRef div with position fixed
          start: "top top", // init slides at the top of the viewport
          end: `+=${sliderArr.length * 100}%`, // intead of using "bottom top" move end marker to the end of 3rd slide to slow down scroll animation

          scrub: true,
          invalidateOnRefresh: true, // to make it responsive
          markers: true
        }
      });

      // each slide
      slides.current.forEach((slide, index) => {
        if (index > 0) {
          slidesTl.current
            .to(slide, {
              clipPath: "polygon(0% 100%, 100% 100%, 100% 0%, 0% 0%)"
            })
            .call(
              () => {
                const _d = slidesTl.current.scrollTrigger.direction;
                setActiveNavItem(index + (_d > 0 ? 0 : _d));
              },
              null,
              "-=0.5"
            );
        }
      });
    });

    return () => {
      ctx.revert();
    };
  }, []);

  const slideToSection = (index) => {
    const factor = navItems.current.length - 1;
    const st = slidesTl.current.scrollTrigger;
    gsap.to(window, {
      scrollTo: {
        y: st.start + (st.end - st.start) * ((1 / factor) * index)
      },
      duration: 1
    });
  };

  return (
    <>
      <section className="container" ref={containerRef}>
        <div className="slides" ref={slidesWrapperRef}>
          {sliderArr.map((slide, index) => {
            return (
              <div
                className={`slide`}
                id={`slide-${index}`}
                aria-hidden={index === activeNavItem ? false : true}
                ref={(element) => {
                  // check if the element exists and if it's not already present
                  if (element && !slides.current.includes(element)) {
                    slides.current.push(element);
                  }
                }}
              >
                <div className="outer">
                  <div className="inner">
                    <a href={slide.href}>
                      <div
                        className="bg"
                        ref={(element) => {
                          if (element && !bg.current.includes(element)) {
                            bg.current.push(element);
                          }
                        }}
                      >
                        <img src={slide.src} alt="" />
                      </div>
                      <span className={`line line-${index}`}></span>
                    </a>
                  </div>
                </div>
              </div>
            );
          })}
        </div>
        <ul className="nav">
          {sliderArr.map(({ navTitle, id }, idx) => {
            return (
              <li
                key={id}
                ref={(element) => {
                  if (element && !navItems.current.includes(element)) {
                    navItems.current.push(element);
                  }
                }}
                className={idx === activeNavItem ? "is-active" : ""}
              >
                <button
                  onClick={() => slideToSection(idx)}
                  data-href={`#slide-${idx}`}
                  type="button"
                >
                  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
                    <path d="M165.013 288.946h75.034c6.953 0 12.609 5.656 12.609 12.608v26.424c0 7.065 3.659 9.585 7.082 9.585 2.106 0 4.451-.936 6.78-2.702l90.964-69.014c3.416-2.589 5.297-6.087 5.297-9.844 0-3.762-1.881-7.259-5.297-9.849l-90.964-69.014c-2.329-1.766-4.674-2.702-6.78-2.702-3.424 0-7.082 2.519-7.082 9.584v26.425c0 6.952-5.656 12.608-12.609 12.608h-75.034c-8.707 0-15.79 7.085-15.79 15.788v34.313c0 8.706 7.082 15.79 15.79 15.79z" />
                    <path d="M256 0C114.842 0 .002 114.84.002 256S114.842 512 256 512s255.998-114.84 255.998-256S397.158 0 256 0zm0 66.785c104.334 0 189.216 84.879 189.216 189.215S360.334 445.215 256 445.215 66.783 360.336 66.783 256 151.667 66.785 256 66.785z" />
                  </svg>
                  <h2>{navTitle}</h2>
                </button>
              </li>
            );
          })}
        </ul>
      </section>
      <section className="container">
        <div className="inner">
          <h1>HELLO!!!</h1>
        </div>
      </section>
      <section className="container">
        <div className="inner">
          <h1>HELLO!!! AGAIN</h1>
        </div>
      </section>
    </>
  );
}

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<App />);

              
            
!
999px

Console