Upper Area
Lower Area

Libraries

  • GSAP v3.12.5
  • GSAP Plugins - ScrollTrigger v3.12.5

Sample Code

Libraries

<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/gsap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/ScrollTrigger.min.js"></script>

index.html

<div class="p-wrapper js-scrollTriggerTarget">
  <div class="p-upper-area">
    <div class="p-upper-area__inner">Upper Area</div>
  </div>
  <div class="p-gallery-area">
    <div class="p-gallery-area__inner js-moveTargetWrapper">
      <div class="p-gallery-area__column js-moveToTop">
        <figure class="p-gallery-area__image">
          <img
            src="/assets/demos/scroll-driven-gallery/img/flower1.jpg"
            alt=""
            width="640"
            height="960"
            decoding="async"
          />
        </figure>
        <figure class="p-gallery-area__image">
          <img
            src="/assets/demos/scroll-driven-gallery/img/flower2.jpg"
            alt=""
            width="640"
            height="960"
            decoding="async"
          />
        </figure>
      </div>
      <div class="p-gallery-area__column js-moveToBottom">
        <figure class="p-gallery-area__image">
          <img
            src="/assets/demos/scroll-driven-gallery/img/flower3.jpg"
            alt=""
            width="640"
            height="960"
            decoding="async"
          />
        </figure>
        <figure class="p-gallery-area__image">
          <img
            src="/assets/demos/scroll-driven-gallery/img/flower4.jpg"
            alt=""
            width="640"
            height="960"
            decoding="async"
          />
        </figure>
      </div>
      <div class="p-gallery-area__column js-moveToTop">
        <figure class="p-gallery-area__image">
          <img
            src="/assets/demos/scroll-driven-gallery/img/flower5.jpg"
            alt=""
            width="640"
            height="960"
            decoding="async"
          />
        </figure>
        <figure class="p-gallery-area__image">
          <img
            src="/assets/demos/scroll-driven-gallery/img/flower6.jpg"
            alt=""
            width="640"
            height="960"
            decoding="async"
          />
        </figure>
      </div>
    </div>
  </div>
  <div class="p-lower-area">
    <div class="p-lower-area__inner">Lower Area</div>
  </div>
</div>

style.css

/* Upper Area */
.p-upper-area {
  display: grid;
  place-content: center;
  height: 100vh;
  margin-bottom: 150vh;
  background-color: #f5f5f5;
}

.p-upper-area__inner {
  font-size: 2.4rem;
  text-align: center;
  font-weight: 500;
}

/* Gallery Area */
.p-gallery-area {
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
}

.p-gallery-area__inner {
  --image-gap: 24px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  column-gap: var(--image-gap, 0);
}

.p-gallery-area__column {
  display: flex;
  flex-direction: column;
  row-gap: var(--image-gap, 0);
}

.p-gallery-area__image {
  --column-count: 3;
  width: calc((100vw - var(--image-gap, 0) * (var(--column-count) - 1)) / var(--column-count));
}

.p-gallery-area__image img {
  width: 100%;
  height: auto;
}

/* Lower Area */
.p-lower-area {
  display: grid;
  place-content: center;
  height: 20vh;
  background-color: #f5f5f5;
}

.p-lower-area__inner {
  font-size: 2.4rem;
  text-align: center;
  font-weight: 500;
}

index.js

document.addEventListener("DOMContentLoaded", () => {
  // デバッグモードを有効にする
  const DEBUG_MODE_ENABLED = true;

  // スクロールトリガーの共通オプション
  const SCROLL_TRIGGER_COMMON_OPTIONS = {
    trigger: ".js-scrollTriggerTarget",
    start: "top center",
    end: "bottom center",
    scrub: true,
    markers: DEBUG_MODE_ENABLED,
  };

  // スクロールトリガーを有効にする
  gsap.registerPlugin(ScrollTrigger);

  // scaleを操作するラッパー要素のアニメーション
  gsap.from(".js-moveTargetWrapper", {
    scale: 1.1,
    scrollTrigger: {
      ...SCROLL_TRIGGER_COMMON_OPTIONS,
    },
  });

  // opacityを操作するラッパー要素のアニメーション
  gsap
    .timeline({
      scrollTrigger: {
        ...SCROLL_TRIGGER_COMMON_OPTIONS,
      },
    })
    .fromTo(
      ".js-moveTargetWrapper",
      { opacity: 0 },
      { opacity: 1, duration: 1 },
    )
    .to(".js-moveTargetWrapper", { opacity: 0.4, duration: 1 });

  // 上に移動するカラムのアニメーション
  gsap.to(".js-moveToTop", {
    y: "10%",
    scrollTrigger: {
      ...SCROLL_TRIGGER_COMMON_OPTIONS,
    },
  });

  // 下に移動するカラムのアニメーション
  gsap.to(".js-moveToBottom", {
    y: "-10%",
    scrollTrigger: {
      ...SCROLL_TRIGGER_COMMON_OPTIONS,
    },
  });
});