<section class="section">
  <div>
    <h1>Reveal Sections on Scroll</h1>
    <p>GSAP & ScrollTrigger - <span>Right-to-left horizontal animation</span></p>
    <p>šŸ‘‡ Scroll down</p>
  </div>
</section>
<section class="section-slides">
  <div class="slides">
    <div class="slide">
      <h2>Check some beautiful <a href="https://unsplash.com/" target="_blank">Unsplash</a> photos!</h2>
    </div>
    <div class="slide">
      <figure>
        <img width="1920" height="1280" src="https://assets.codepen.io/162656/gallery-edinburgh.jpg" alt="edinburgh" />
        <figcaption>
          <div class="caption">
            <h2 class="heading">Edinburgh</h2>
            <p class="content">The capital of Scotland</p>
          </div>
        </figcaption>
      </figure>
    </div>
    <div class="slide">
      <figure>
        <img width="1920" height="1005" src="https://assets.codepen.io/162656/gallery-berlin.jpg" alt="berlin" />
        <figcaption>
          <div class="caption">
            <h2 class="heading">Berlin</h2>
            <p class="content">The capital of Germany</p>
          </div>
        </figcaption>
      </figure>
    </div>
    <div class="slide">
      <figure>
        <img width="1920" height="1282" src="https://assets.codepen.io/162656/gallery-havana.jpg" alt="havana" />
        <figcaption>
          <div class="caption">
            <h2 class="heading">Havana</h2>
            <p class="content">The capital of Cuba</p>
          </div>
        </figcaption>
      </figure>
    </div>
    <div class="slide">
      <figure>
        <img width="1920" height="1279" src="https://assets.codepen.io/162656/gallery-london.jpg" alt="london" />
        <figcaption>
          <div class="caption">
            <h2 class="heading">London</h2>
            <p class="content">The capital city of United Kingdom</p>
          </div>
        </figcaption>
      </figure>
    </div>
    <div class="slide">
      <figure>
        <img width="1920" height="1439" src="https://assets.codepen.io/162656/gallery-athens.jpg" alt="athens" />
        <figcaption>
          <div class="caption">
            <h2 class="heading">Athens</h2>
            <p class="content">The capital city of Greece</p>
          </div>
        </figcaption>
      </figure>
    </div>
    <div class="slide">
      <figure>
        <img width="1920" height="1281" src="https://assets.codepen.io/162656/gallery-vienna.jpg" alt="vienna" />
        <figcaption>
          <div class="caption">
            <h2 class="heading">Vienna</h2>
            <p class="content">The capital of Austria</p>
          </div>
        </figcaption>
      </figure>
    </div>
    <div class="slide">
      <h2>End of horizontal scrolling</h2>
    </div>
  </div>
</section>
<section class="section">
  <h2>Thank you!</h2>
</section>

<footer class="page-footer">
  <span>made by </span>
  <a href="https://georgemartsoukos.com/" target="_blank">
    <img width="24" height="24" src="https://assets.codepen.io/162656/george-martsoukos-small-logo.svg" alt="George Martsoukos logo">
  </a>
</footer>
/* BASIC STYLES
ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ */
@import url("https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap");

* {
  box-sizing: border-box;
}

body {
  font-family: "Montserrat", sans-serif;
  margin: 0;
}

a {
  color: currentColor;
}

.section {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 15px;
  height: 100vh;
  text-align: center;
  color: white;
  background: #003049;
}

.section span {
  text-decoration: underline;
}

/* MAIN STYLES
ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ */
.section-slides {
  margin-top: -1px;
  overflow: hidden;
}

.slides {
  display: flex;
}

.slide:first-child,
.slide:last-child,
.slide figure {
  width: 100vw;
  height: 100vh;
  flex-shrink: 0;
}

.slide:first-child,
.slide:last-child {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: #fcbf49;
}

.slide figure {
  margin: 0;
  position: relative;
  width: 100vw;
  height: 100vh;
}

.slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #f1faee;
}

.slide figcaption {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.15);
}

.slide .caption {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.slide .caption > * {
  display: inline-block;
  padding: 5px 15px;
  font-weight: bold;
  text-align: center;
}

.slide .heading {
  margin: 0 0 10px;
  font-size: clamp(2.5rem, 2vh, 5rem);
  line-height: 1;
  color: #d62828;
  background: #fcbf49;
}

.slide .content {
  font-size: 1.5em;
  color: white;
  margin: 0;
  background: #ef476f;
}

/* FOOTER STYLES
ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ā€“ */
.page-footer {
  position: fixed;
  right: 0;
  bottom: 50px;
  display: flex;
  align-items: center;
  padding: 5px;
  z-index: 1;
  font-size: 14px;
  background: white;
}

.page-footer a {
  display: flex;
  margin-left: 4px;
}
const slides = gsap.utils.toArray(".slide");
const captions = gsap.utils.toArray(".caption");
const headings = gsap.utils.toArray(".heading");
const p = gsap.utils.toArray(".content");

gsap.set(headings, { opacity: 0, y: -100, transformOrigin: "top" });
gsap.set(p, { opacity: 0, y: 100, transformOrigin: "bottom" });

const tween = gsap.to(".slide", {
  ease: "none",
  xPercent: -100 * (slides.length - 1)
});

ScrollTrigger.create({
  trigger: ".slides",
  start: "top top",
  end: "+=500%",
  scrub: true,
  pin: true,
  animation: tween
  //markers: true
});

captions.forEach((caption) => {
  const items = caption.querySelectorAll("*");
  gsap.to(items, {
    opacity: 1,
    y: 0,
    duration: 1.5,
    scrollTrigger: {
      trigger: caption,
      start: "left right-=20%",
      end: "left left+=20%",
      scrub: true,
      containerAnimation: tween
      //markers: true
    }
  });
});

/*Another way of setting the previous code*/
/*captions.forEach((caption) => {
  ScrollTrigger.create({
    trigger: caption,
    start: "left right-=20%",
    end: "left left+=20%",
    scrub: true,
    animation: gsap.to(caption.querySelectorAll("*"), {
      opacity: 1,
      y: 0,
      duration: 1.5
    }),
    containerAnimation: tween,
    markers: true
  });
});*/

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://unpkg.com/gsap@3/dist/gsap.min.js
  2. https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/ScrollTrigger.min.js