Codrops 원본

Creating a Smooth Horizontal Parallax Gallery: From DOM to WebGL

섹션 · MIT

섹션 더 보기
ORIGINAL PREVIEW
Creating a Smooth Horizontal Parallax Gallery: From DOM to WebGL 정적 미리보기

갤러리 안에서는 화면을 벗어나거나 움직임을 멈추면 예제도 닫힙니다. 다시 재생할 때는 처음부터 시작해요.

큰 화면으로 보기 새 탭

SOURCE FILES

원본 코드 읽기

17개 파일

수집한 원본 소스와 실행 안내를 함께 제공합니다.

css/base.css
파일 저장

*,
*::after,
*::before {
  box-sizing: border-box;
}

:root {
  font-size: 12px;
  --color-text: #fff;
  --color-bg: #000;
  --color-link: #fff;
  --color-link-hover: #fff;
  --page-padding: 1.5rem;
}

body {
  margin: 0;
  color: var(--color-text);
  background-color: var(--color-bg);
  font-family: ui-monospace, monospace;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
}

@media (scripting: enabled) {
  .loading {
    &::before,
    &::after {
      content: '';
      position: fixed;
      z-index: 10000;
    }

    &::before {
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: var(--color-bg);
    }

    &::after {
      top: 50%;
      left: 50%;
      width: 100px;
      height: 1px;
      margin: 0 0 0 -50px;
      background: var(--color-link);
      animation: loaderAnim 1.5s ease-in-out infinite alternate forwards;
    }
  }
}

@keyframes loaderAnim {
  0% {
    transform: scaleX(0);
    transform-origin: 0% 50%;
  }

  50% {
    transform: scaleX(1);
    transform-origin: 0% 50%;
  }

  50.1% {
    transform: scaleX(1);
    transform-origin: 100% 50%;
  }

  100% {
    transform: scaleX(0);
    transform-origin: 100% 50%;
  }
}

a {
  text-decoration: none;
  color: var(--color-link);
  outline: none;
  cursor: pointer;

  &:hover {
    text-decoration: underline;
    color: var(--color-link-hover);
  }

  &:focus {
    outline: none;
    background: lightgrey;

    &:not(:focus-visible) {
      background: transparent;
    }

    &:focus-visible {
      outline: 2px solid red;
      background: transparent;
    }
  }
}

.frame {
  padding: 3rem var(--page-padding) 0;
  display: grid;
  z-index: 1000;
  position: relative;
  grid-row-gap: 2rem;
  grid-column-gap: 2rem;
  pointer-events: none;
  justify-items: start;
  grid-template-columns: auto auto auto 1fr;
  grid-template-areas:
    'title title title title'
    'back archive github ...'
    'demos demos demos demos'
    'tags tags tags tags'
    'sponsor sponsor sponsor sponsor';

  #cdawrap {
    justify-self: start;
    grid-area: sponsor;
  }

  a,
  button {
    pointer-events: auto;
  }

  .frame__title {
    grid-area: title;
    font-size: inherit;
    margin: 0;
  }

  .frame__back {
    grid-area: back;
    justify-self: start;
  }

  .frame__archive {
    grid-area: archive;
    justify-self: start;
  }

  .frame__github {
    grid-area: github;
  }

  .frame__tags {
    grid-area: tags;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
  }

  .frame__demos {
    grid-area: demos;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
  }

  @media screen and (min-width: 53em) {
    padding: var(--page-padding);
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    grid-template-columns: auto auto auto auto 1fr;
    grid-template-rows: auto auto 1fr;
    align-content: start;
    grid-template-areas:
      'title back github archive ...'
      'demos demos demos ... ...'
      'tags tags tags sponsor sponsor';

    .frame__tags {
      align-self: end;
    }

    #cdawrap {
      justify-self: end;
      align-self: end;
      text-align: right;
      max-width: 300px;
    }
  }
}

.button {
  border: 1px solid #4c4c4c;
  padding: 0.5rem 1rem;
  border-radius: 2em;
}

a.button:hover,
a.button:focus {
  border-color: #5c5c5c;
  text-decoration: none;
  color: #fff;
}

.content {
  padding: var(--page-padding);
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  position: relative;

  @media screen and (min-width: 53em) {
    min-height: 100vh;
    justify-content: center;
    align-items: center;
  }
}

canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}
index.html
파일 저장

<!doctype html>
<html lang="en" class="no-js">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Horizontal Parallax Gallery | Codrops</title>
  <meta name="author" content="David Faure for Codrops" />
  <link
        rel="icon"
        type="image/svg+xml"
        href="https://tympanus.net/favicon/favicon.svg" />
  <link rel="shortcut icon" href="https://tympanus.net/favicon/favicon.ico" />
  <link rel="stylesheet" type="text/css" href="css/base.css" />
  <script>
    document.documentElement.className = "js";
  </script>
</head>

<body class="demo-1 loading">
  <main>
    <header class="frame">
      <h1 class="frame__title">Horizontal Parallax Gallery (2D/DOM)</h1>
      <a class="frame__back" href="https://tympanus.net/codrops/?p=108925">Tutorial</a>
      <a class="frame__archive" href="https://tympanus.net/codrops/hub/">All demos</a>
      <a class="frame__github" href="https://github.com/davidfaure/horizontal-parallax-gallery-codrops">GitHub</a>
      <nav class="frame__tags">
        <a href="https://tympanus.net/codrops/demos/?tag=scroll">#scroll</a>
        <a href="https://tympanus.net/codrops/demos/?tag=three-js">#three.js</a>
        <a href="https://tympanus.net/codrops/demos/?tag=webgl">#webgl</a>
      </nav>
      <nav class="frame__demos">
        <a class="button" href="index2.html">WebGL Version</a>
      </nav>
    </header>
    <div class="content">
      <div class="gallery__wrapper">
        <div class="gallery__image__container">
          <picture class="gallery__media">
            <img
                 src="1.webp"
                 alt="Image 1"
                 class="gallery__media__image"
                 draggable="false" />
          </picture>
          <picture class="gallery__media">
            <img
                 src="2.webp"
                 alt="image_2"
                 class="gallery__media__image"
                 draggable="false" />
          </picture>
          <picture class="gallery__media">
            <img
                 src="3.webp"
                 alt="image_3"
                 class="gallery__media__image"
                 draggable="false" />
          </picture>
          <picture class="gallery__media">
            <img
                 src="4.webp"
                 alt="image_4"
                 class="gallery__media__image"
                 draggable="false" />
          </picture>
          <picture class="gallery__media">
            <img
                 src="5.webp"
                 alt="image_5"
                 class="gallery__media__image"
                 draggable="false" />
          </picture>
          <picture class="gallery__media">
            <img
                 src="6.webp"
                 alt="image_6"
                 class="gallery__media__image"
                 draggable="false" />
          </picture>
          <picture class="gallery__media">
            <img
                 src="7.webp"
                 alt="image_7"
                 class="gallery__media__image"
                 draggable="false" />
          </picture>
          <picture class="gallery__media">
            <img
                 src="8.webp"
                 alt="image_8"
                 class="gallery__media__image"
                 draggable="false" />
          </picture>
          <picture class="gallery__media">
            <img
                 src="9.webp"
                 alt="image_9"
                 class="gallery__media__image"
                 draggable="false" />
          </picture>
          <picture class="gallery__media">
            <img
                 src="10.webp"
                 alt="image_1"
                 class="gallery__media__image"
                 draggable="false" />
          </picture>
        </div>
      </div>
    </div>
  </main>
  <script type="module" src="./src/main.ts"></script>
</body>

</html>
함께 쓰는 파일 15개 보기
index2.html
파일 저장

<!doctype html>
<html lang="en" class="no-js">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Horizontal Parallax Gallery | 2D/DOM Version | Codrops</title>
  <meta name="author" content="Codrops" />
  <link
        rel="icon"
        type="image/svg+xml"
        href="https://tympanus.net/favicon/favicon.svg" />
  <link rel="shortcut icon" href="https://tympanus.net/favicon/favicon.ico" />
  <link rel="stylesheet" type="text/css" href="css/base.css" />
  <script>
    document.documentElement.className = "js";
  </script>
</head>

<body class="demo-2 loading" id="gl">
  <main>
    <header class="frame">
      <h1 class="frame__title">Horizontal Parallax Gallery (WebGL)</h1>
      <a class="frame__back" href="https://tympanus.net/codrops/?p=108925">Tutorial</a>
      <a class="frame__archive" href="https://tympanus.net/codrops/hub/">All demos</a>
      <a class="frame__github" href="https://github.com/davidfaure/horizontal-parallax-gallery-codrops">GitHub</a>
      <nav class="frame__tags">
        <a href="https://tympanus.net/codrops/demos/?tag=scroll">#scroll</a>
        <a href="https://tympanus.net/codrops/demos/?tag=three-js">#three.js</a>
        <a href="https://tympanus.net/codrops/demos/?tag=webgl">#webgl</a>
      </nav>
      <nav class="frame__demos">
        <a class="button" href="index.html">2D/DOM Version</a>
      </nav>
    </header>
    <div class="content">
      <div class="gallery__wrapper__gl">
        <div class="gallery__image__container__gl">
          <picture class="gallery__media__gl">
            <img
                 src="1.webp"
                 alt="Image 1"
                 class="gallery__media__image__gl"
                 draggable="false" />
          </picture>
          <picture class="gallery__media__gl">
            <img
                 src="2.webp"
                 alt="image_2"
                 class="gallery__media__image__gl"
                 draggable="false" />
          </picture>
          <picture class="gallery__media__gl">
            <img
                 src="3.webp"
                 alt="image_3"
                 class="gallery__media__image__gl"
                 draggable="false" />
          </picture>
          <picture class="gallery__media__gl">
            <img
                 src="4.webp"
                 alt="image_4"
                 class="gallery__media__image__gl"
                 draggable="false" />
          </picture>
          <picture class="gallery__media__gl">
            <img
                 src="5.webp"
                 alt="image_5"
                 class="gallery__media__image__gl"
                 draggable="false" />
          </picture>
          <picture class="gallery__media__gl">
            <img
                 src="6.webp"
                 alt="image_6"
                 class="gallery__media__image__gl"
                 draggable="false" />
          </picture>
          <picture class="gallery__media__gl">
            <img
                 src="7.webp"
                 alt="image_7"
                 class="gallery__media__image__gl"
                 draggable="false" />
          </picture>
          <picture class="gallery__media__gl">
            <img
                 src="8.webp"
                 alt="image_8"
                 class="gallery__media__image__gl"
                 draggable="false" />
          </picture>
          <picture class="gallery__media__gl">
            <img
                 src="9.webp"
                 alt="image_9"
                 class="gallery__media__image__gl"
                 draggable="false" />
          </picture>
          <picture class="gallery__media__gl">
            <img
                 src="10.webp"
                 alt="image_1"
                 class="gallery__media__image__gl"
                 draggable="false" />
          </picture>
        </div>
      </div>
    </div>
  </main>
  <script type="module" src="./src/main.ts"></script>
</body>

</html>
src/gallery/GL.ts
파일 저장

import * as THREE from "three";
import { GLMedia } from "./GLMedia";
import GUI from "lil-gui";

export interface Sizes {
  width: number;
  height: number;
}

export class GL {
  renderer: THREE.WebGLRenderer;
  scene: THREE.Scene;
  camera: THREE.PerspectiveCamera;
  geometry!: THREE.PlaneGeometry;
  group: THREE.Group;
  screen: Sizes = {
    width: window.innerWidth,
    height: window.innerHeight,
  };
  medias!: HTMLElement[];
  allMedias!: GLMedia[];
  gui!: GUI;
  params = {
    parallaxIntensity: 0.4,
    uvScale: 0.85,
    shaderMultiplier: 1.0,
  };

  constructor() {
    this.renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
    this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
    document.body.appendChild(this.renderer.domElement);

    this.scene = new THREE.Scene();
    const fov = 2 * Math.atan(this.screen.height / 2 / 100) * (180 / Math.PI);

    this.camera = new THREE.PerspectiveCamera(
      fov,
      this.screen.width / this.screen.height,
      0.01,
      1000,
    );
    this.camera.position.set(0, 0, 100);
    this.group = new THREE.Group();
    this.medias = Array.from(
      document.querySelectorAll(".gallery__media__image__gl"),
    );
    this.createGeometry();
    this.createGallery();
    this.setupGUI();
  }

  createGeometry() {
    this.geometry = new THREE.PlaneGeometry(1, 1, 32, 32);
  }
  createGallery() {
    this.allMedias = this.medias.map((media) => {
      return new GLMedia({
        scene: this.group,
        element: media,
        viewport: this.screen,
        camera: this.camera,
        geometry: this.geometry,
        renderer: this.renderer,
      });
    });

    this.scene.add(this.group);
  }

  setupGUI() {
    this.gui = new GUI();

    this.gui
      .add(this.params, "parallaxIntensity", 0, 1, 0.01)
      .name("Parallax Intensity")
      .onChange((value: number) => {
        this.allMedias.forEach((media) => {
          media.parallaxIntensity = value;
        });
      });

    this.gui
      .add(this.params, "uvScale", 0.7, 1.0, 0.01)
      .name("UV Scale (Buffer)")
      .onChange((value: number) => {
        this.allMedias.forEach((media) => {
          media.material.uniforms.uUvScale.value = value;
        });
      });

    this.gui
      .add(this.params, "shaderMultiplier", 0, 2, 0.1)
      .name("Shader Multiplier")
      .onChange((value: number) => {
        this.allMedias.forEach((media) => {
          media.material.uniforms.uShaderMultiplier.value = value;
        });
      });
  }

  onResize(
    viewport: Sizes = { width: window.innerWidth, height: window.innerHeight },
  ) {
    this.screen = viewport;

    this.camera.aspect = this.screen.width / this.screen.height;
    this.camera.fov =
      2 * Math.atan(this.screen.height / 2 / 100) * (180 / Math.PI);
    this.camera.updateProjectionMatrix();

    this.renderer.setSize(this.screen.width, this.screen.height);
    this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));

    this.allMedias.forEach((media) => {
      media.onResize(this.screen);
    });
  }

  render(scroll: number) {
    this.allMedias.forEach((media) => {
      media.render(scroll);
    });
    this.renderer.render(this.scene, this.camera);
  }
}
src/gallery/GLMedia.ts
파일 저장

import * as THREE from "three";
import vertex from "../shaders/mediaVertex.glsl";
import fragment from "../shaders/mediaFragment.glsl";

interface Props {
  scene: THREE.Group;
  element: HTMLElement;
  viewport: { width: number; height: number };
  camera: THREE.PerspectiveCamera;
  geometry: THREE.PlaneGeometry;
  renderer: THREE.WebGLRenderer;
}

export class GLMedia {
  camera: THREE.PerspectiveCamera;
  element: HTMLElement;
  scene: THREE.Group;
  geometry: THREE.PlaneGeometry;
  renderer: THREE.WebGLRenderer;
  material!: THREE.ShaderMaterial;
  texture!: THREE.Texture;
  viewport!: { width: number; height: number };
  bounds!: DOMRect;
  mesh!: THREE.Mesh;
  parallaxIntensity: number;

  constructor({ scene, element, viewport, camera, geometry, renderer }: Props) {
    this.scene = scene;
    this.element = element;
    this.viewport = viewport;
    this.camera = camera;
    this.geometry = geometry;
    this.renderer = renderer;

    this.parallaxIntensity = 0.4;
    this.bounds = this.element.getBoundingClientRect();
    this.createMesh();
    this.createTexture();
  }

  createMesh() {
    this.material = new THREE.ShaderMaterial({
      uniforms: {
        uTexture: { value: null },
        uResolution: {
          value: new THREE.Vector2(
            this.bounds?.width || 1,
            this.bounds?.height || 1,
          ),
        },
        uImageResolution: { value: new THREE.Vector2(1, 1) },
        uParallax: { value: 0 },
        uUvScale: { value: 0.85 },
        uShaderMultiplier: { value: 1.0 },
      },
      vertexShader: vertex,
      fragmentShader: fragment,
    });

    this.mesh = new THREE.Mesh(this.geometry, this.material);
    this.scene.add(this.mesh);
  }

  createTexture() {
    this.texture = new THREE.TextureLoader().load(
      this.element.getAttribute("src") as string,
      (text) => {
        const material = this.mesh?.material as THREE.ShaderMaterial;
        if (material?.uniforms?.uImageResolution) {
          material.uniforms.uImageResolution.value.set(
            text.image.width,
            text.image.height,
          );
        }
      },
    );

    this.material.uniforms.uTexture.value = this.texture;
  }

  updateScale() {
    this.bounds = this.element.getBoundingClientRect();
    this.mesh?.scale.set(this.bounds.width, this.bounds.height, 1);
    this.material?.uniforms.uResolution.value.set(
      this.bounds.width,
      this.bounds.height,
    );
  }

  updatePosition(scroll: number) {
    const x =
      this.bounds.left -
      scroll -
      this.viewport.width / 2 +
      this.bounds.width / 2;
    const y =
      -this.bounds.top + this.viewport.height / 2 - this.bounds.height / 2;

    this.mesh.position.set(x, y, 0);
  }

  updateParallax(scroll: number) {
    if (!this.bounds) return;

    const { innerWidth } = window;

    const elementLeft = this.bounds.left - scroll;
    const elementRight = elementLeft + this.bounds.width;

    if (elementRight >= 0 && elementLeft <= innerWidth) {
      // Calculate parallax value based on element position in viewport
      // Range from -1 to 1 as element moves through viewport
      const elementCenter = elementLeft + this.bounds.width / 2;
      const viewportCenter = innerWidth / 2;
      const distance = (elementCenter - viewportCenter) / innerWidth;

      // UV parallax with stronger effect
      const parallaxValue = distance * this.parallaxIntensity;
      this.material.uniforms.uParallax.value = parallaxValue;
    }
  }

  render(scroll: number) {
    this.updateParallax(scroll);
    this.updatePosition(scroll);
  }

  onResize(viewport: { width: number; height: number }) {
    this.viewport = viewport;
    this.updateScale();
  }
}
src/gallery/gallery.css
파일 저장

.gallery__wrapper {
  position: relative;
  width: 100%;
  overflow: hidden;
  user-select: none;
}

.gallery__wrapper__gl {
  position: relative;
  width: 100%;
  overflow: hidden;
  user-select: none;
}

.gallery__image__container,
.gallery__image__container__gl {
  display: flex;
  gap: 2rem;
  will-change: transform;
  height: 100%;
}

.gallery__media,
.gallery__media__gl,
.gallery__empty__gl {
  flex-shrink: 0;
  aspect-ratio: 4 / 3;
  max-height: 60vh;
  height: 60vh;
  overflow: hidden;
  position: relative;
  display: block;
}

.gallery__media__image {
  position: absolute;
  top: 0;
  left: -12.5%;
  width: 125%;
  height: 100%;
  object-fit: cover;
}

.gallery__media__image__gl {
  position: absolute;
  opacity: 0;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
src/gallery/index.ts
파일 저장

import './gallery.css';

export class Gallery {
  container: HTMLElement | null;
  wrapper: HTMLElement | null;
  images: NodeListOf<HTMLElement>;

  constructor() {
    this.container = document.querySelector('.gallery__image__container');
    this.wrapper = document.querySelector('.gallery__wrapper');
    this.images = document.querySelectorAll('.gallery__media__image');
  }

  private clamp(v: number, min: number, max: number) {
    return Math.max(min, Math.min(max, v));
  }

  applyParallaxEffect() {
    const vw = window.innerWidth;
    const viewportCenter = vw * 0.5;

    this.images.forEach((image) => {
      const parent = image.parentElement as HTMLElement;
      if (!parent) return;

      const rect = parent.getBoundingClientRect();
      const elementCenter = rect.left + rect.width * 0.5;

      // -1 (left) .. 0 (center) .. 1 (right)
      const t = this.clamp((elementCenter - viewportCenter) / viewportCenter, -1, 1);

      // For CSS: image width 125% (extra 25% => 12.5% each side)
      // translateX(%) is relative to image width (125%), so safe max ~= 10%
      const maxShift = 10;

      const shift = -t * maxShift; // counter-motion
      image.style.transform = `translate3d(${shift}%, 0, 0)`;
    });
  }

  render(container: HTMLElement, scroll: number) {
    container.style.transform = `translateX(${scroll < 0.01 ? 0 : -scroll}px)`;
    this.applyParallaxEffect();
  }
}
src/main.ts
파일 저장

import { Gallery } from "./gallery";
import { GL } from "./gallery/GL";
import { clamp, lerp } from "./utils/math";

interface Scroll {
  current: number;
  target: number;
  ease: number;
  limit: number;
}

class App {
  container: HTMLElement | null;
  wrapper: HTMLElement | null;
  images: NodeListOf<HTMLElement>;
  scroll: Scroll;
  gallery!: Gallery;
  gl!: HTMLElement | null;
  canvas!: GL | null;

  constructor() {
    this.container =
      document.querySelector(".gallery__image__container") ||
      document.querySelector(".gallery__image__container__gl");
    this.wrapper =
      document.querySelector(".gallery__wrapper") ||
      document.querySelector(".gallery__wrapper__gl");
    this.images = document.querySelectorAll(".gallery__media__image");
    this.gl = document.getElementById("gl");
    this.scroll = {
      current: 0,
      target: 0,
      ease: 0.07,
      limit: 0,
    };

    this.preloadImages().then(() => {
      document.body.classList.remove("loading");
      this.init();
      this.setLimit();
      this.onResize();
      this.addEventListeners();
      this.render();
    });
  }

  preloadImages(): Promise<void[]> {
    const images = Array.from(document.querySelectorAll("img"));
    const promises = images.map((img) => {
      return new Promise<void>((resolve) => {
        const image = new Image();
        image.onload = () => resolve();
        image.onerror = () => resolve();
        image.src = img.src;
      });
    });
    return Promise.all(promises);
  }

  init() {
    this.gallery = new Gallery();
    if (this.gl) {
      this.canvas = new GL();
    }
  }

  setLimit() {
    if (!this.container || !this.wrapper) return;
    this.scroll.limit = this.container.scrollWidth - this.wrapper.clientWidth;
  }

  onWheel(e: WheelEvent) {
    this.scroll.target += e.deltaY;
  }

  onResize() {
    this.setLimit();
    this.canvas?.onResize({
      width: window.innerWidth,
      height: window.innerHeight,
    });
  }

  addEventListeners() {
    window.addEventListener("resize", this.onResize.bind(this));
    window.addEventListener("wheel", this.onWheel.bind(this), {
      passive: true,
    });
  }

  render() {
    this.scroll.target = clamp(0, this.scroll.limit, this.scroll.target);

    this.scroll.current = lerp(
      this.scroll.current,
      this.scroll.target,
      this.scroll.ease,
    );

    this.gallery?.render(this.container!, this.scroll.current);
    this.canvas?.render(this.scroll.current);

    requestAnimationFrame(this.render.bind(this));
  }
}

new App();
src/shaders/mediaFragment.glsl
파일 저장

precision highp float;

varying vec2 vUv;

uniform sampler2D uTexture;
uniform vec2 uResolution;
uniform vec2 uImageResolution;
uniform float uParallax;
uniform float uUvScale;
uniform float uShaderMultiplier;

vec2 coverUv(vec2 uv, vec2 resolution, vec2 imageResolution) {
  vec2 ratio = vec2(
    min((resolution.x / resolution.y) / (imageResolution.x / imageResolution.y), 1.0),
    min((resolution.y / resolution.x) / (imageResolution.y / imageResolution.x), 1.0)
  );

  return vec2(
    uv.x * ratio.x + (1.0 - ratio.x) * 0.5,
    uv.y * ratio.y + (1.0 - ratio.y) * 0.5
  );
}


void main() {
  vec2 uv = coverUv(vUv, uResolution, uImageResolution);

  // Apply parallax effect (horizontal instead of vertical)
  uv.x += uParallax * uShaderMultiplier; // Increased multiplier from 0.5 to 1.0 for stronger effect

  // Scale UV to create "parent container" effect
  // This makes the texture slightly smaller, creating space for parallax movement
  uv -= 0.5;
  uv *= uUvScale; // Increased from 0.92 to allow more parallax movement
  uv += 0.5;

  vec3 col = texture2D(uTexture, uv).rgb;

  gl_FragColor = vec4(col, 1.);
}
src/shaders/mediaVertex.glsl
파일 저장

#define PI 3.1415926535897932384626433832795
precision highp float;

varying vec2 vUv;

void main() {
    vUv = uv;
    gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
src/utils/data.ts
파일 저장

export const galleries = [
  {
    id: 1,
    src: "/1.webp",
    alt: "image_1",
  },
  {
    id: 2,
    src: "/2.webp",
    alt: "image_2",
  },
  {
    id: 3,
    src: "/3.webp",
    alt: "image_3",
  },
  {
    id: 4,
    src: "/4.webp",
    alt: "image_4",
  },
  {
    id: 5,
    src: "/5.webp",
    alt: "image_5",
  },
  {
    id: 6,
    src: "/6.webp",
    alt: "image_6",
  },
  {
    id: 7,
    src: "/7.webp",
    alt: "image_7",
  },
  {
    id: 8,
    src: "/8.webp",
    alt: "image_8",
  },
  {
    id: 9,
    src: "/9.webp",
    alt: "image_9",
  },
  {
    id: 10,
    src: "/10.webp",
    alt: "image_10",
  },
];
src/utils/math.ts
파일 저장

import GSAP from "gsap";

export function lerp(p1: number, p2: number, t: number): number {
  return GSAP.utils.interpolate(p1, p2, t);
}

export function clamp(min: number, max: number, value: number): number {
  return GSAP.utils.clamp(min, max, value);
}
src/vite-env.d.ts
파일 저장

/// <reference types="vite/client" />

declare module "*.glsl" {
  const value: string;
  export default value;
}

declare module "*.vert" {
  const value: string;
  export default value;
}

declare module "*.frag" {
  const value: string;
  export default value;
}
vite.config.js
파일 저장

import { fileURLToPath } from "url";
import { dirname, resolve } from "path";
import { defineConfig } from "vite";
import glsl from "vite-plugin-glsl";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export default defineConfig({
  plugins: [glsl()],
  base: "./",
  resolve: {
    alias: {
      "@": resolve(__dirname, "src"),
    },
  },
  build: {
    rollupOptions: {
      input: {
        demo1: resolve(__dirname, "index.html"),
        demo2: resolve(__dirname, "index2.html"),
      },
    },
  },
});
Media credits and license evidence실행 안내·자료
파일 저장

README.md
## Credits

- Images generated with [Midjourney](https://midjourney.com)


## License

[MIT](LICENSE)
LICENSE실행 안내·자료
파일 저장

MIT License

Copyright (c) 2009 - 2025 [Codrops](https://codrops.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Bundled dependency licenses실행 안내·자료
파일 저장

GSAP standard license snapshot
Source: https://gsap.com/community/standard-license/
Retrieved: 2026-09-22T04:22:49.089Z
Original distribution copyright and version headers remain in the runtime code.

Standard "No Charge" GSAP License

 I. DEFINITIONS

 “GSAP License” means the terms and conditions of this GSAP Software License Agreement.

 "GSAP Products" means any Software made available at gsap.com (https://gsap.com) or any successor sites, including but not limited to the GSAP animation library and related plugins, tools, or extensions.

 "Permitted Uses" means the implementation and/or use of GSAP Products on any website, web application, or digital interface by any person or entity (which may include, for clarity, those of companies that compete with Webflow in other areas of business).

 "Prohibited Uses" means any implementation and/or use of GSAP Products in tools that allow users to build visual animations without code that encourages, induces, or materially assists in creating a solution that competes with Webflow’s visual animation building capabilities.

 "Competitive Products" means any software, tool, or service that enables users to create, edit, or manage animations through a visual interface or builder similar to Webflow (https://webflow.com).

 II. GRANT OF LICENSE

 Subject to the terms and conditions of this GSAP License, Webflow grants you a non-exclusive, worldwide license to use, reproduce, display, and implement GSAP Products solely for Permitted Uses.

 III. RESTRICTIONS

 You may not:

 Use any GSAP Products for any Prohibited Uses without prior written consent;

 Reverse engineer any GSAP Products for the purpose of creating Competitive Products;

 Remove or alter any proprietary notices or branding from GSAP Products.

 IV. OWNERSHIP AND INTELLECTUAL PROPERTY

 All intellectual property rights in GSAP Products, including but not limited to copyright, patents, trademarks, and trade secrets, remain the exclusive property of Webflow. This GSAP License does not transfer any ownership rights in GSAP Products to you.

 V. TERMINATION

 Webflow may terminate this GSAP License and revoke your access in its discretion if you fail to comply with any of these terms and conditions. Upon termination, you must cease all use of GSAP Products and destroy all copies in your possession.

 VI. MISCELLANEOUS PROVISIONS

 General: This GSAP License is incorporated into and subject to Webflow’s Terms of Service available here (https://webflow.com/legal/terms) ("Terms of Service"). In the event of any conflict or inconsistency between this GSAP License and the Terms of Service, the terms of this GSAP License shall govern in relation to your use of any GSAP Products.

 Amendments: Webflow reserves the right to update or modify this GSAP License at any time by posting the revised terms on this website, provided that any such updates or modifications shall not result in any material degradation to the security, integrity, or functionality of any GSAP Products. You understand and agree that your continued use of any GSAP Products after such revisions to this GSAP License constitutes your acceptance of this GSAP License as revised. If you do not accept the revised GSAP License, you are prohibited from using versions of the GSAP Products released after the effective date of the revised GSAP License (as well as any updates made to previous versions). Notwithstanding, you may continue using previous versions of GSAP Products under the applicable terms licensed to you prior to the effective date of the revised GSAP License (for clarity, excluding any updates made thereto).

 No Waiver: Failure of Webflow to enforce any provision of this GSAP License shall not constitute a waiver of future enforcement of that or any other provision.

 FAQ

 Is it acceptable for AI tools like ChatGPT, Cursor, Lovable, Webstudio, etc. to generate GSAP code?
 Absolutely! AI-generated code is not a "Prohibited Use".

 What if a WordPress plugin or theme or other niche tool allows users to create GSAP-driven effects through a visual interface? Is that prohibited?
 We want to encourage developers to build on top of GSAP, including visual tools that don't directly compete with Webflow's rich animation-building capabilities. If you are not sure if your product might be considered a "Prohibited Use", feel free to contact us (https://gsap.com/contact) so we can talk through it!

 Can I really use GSAP in commercial projects without paying anything?
 Yes, really! Commercial usage is covered under the standard license. All of GSAP including the plugins that were formerly "members-only" like SplitText (https://gsap.com/docs/v3/Plugins/SplitText/) and MorphSVG (https://gsap.com/docs/v3/Plugins/MorphSVGPlugin) can be used in commercial projects at no charge. Enjoy! 💚

 Effective date: April 30, 2025

 Last modified date: May 30, 2025

 Copyright (©) 2025, Webflow


three@0.182.0 — LICENSE
The MIT License

Copyright © 2010-2025 three.js authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


lil-gui@0.21.0 — LICENSE.md
MIT License

Copyright (c) 2019 George Michael Brower

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.