Codrops 원본

Building a Layered Zoom Scroll Effect with GSAP ScrollSmoother and ScrollTrigger

스크롤 · MIT

스크롤 더 보기
ORIGINAL PREVIEW
Building a Layered Zoom Scroll Effect with GSAP ScrollSmoother and ScrollTrigger 정적 미리보기

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

큰 화면으로 보기 새 탭

SOURCE FILES

원본 코드 읽기

9개 파일

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

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>Telescope Zoom Animation on Scroll | Codrops</title>
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <meta name="author" content="Codrops" />
    <link rel="stylesheet" href="https://use.typekit.net/tuz3bfv.css" />
    <link rel="shortcut icon" href="https://tympanus.net/favicon/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="./src/base.css" />
    <script>
      document.documentElement.className = 'js';
    </script>
  </head>

  <body class="loading">
    <main>
      <header class="frame">
        <h1 class="frame__title">
          Telescope Zoom Animation on
          <a href="https://tympanus.net/codrops/demos/?tag=scrolling">#Scroll</a>
          with
          <a href="https://tympanus.net/codrops/demos/?tag=gsap">#GSAP</a>
        </h1>
        <a class="frame__back" href="https://tympanus.net/codrops/?p=102554">Tutorial</a>
        <a class="frame__archive" href="https://tympanus.net/codrops/hub/">All demos</a>
        <a class="frame__github" href="https://github.com/joffreysp/telescope-zoom">GitHub</a>
      </header>

      <div class="wrapper">
        <div class="content">
          <div class="section">
            <h1>
              <span class="left">for the</span>
              <span class="right">planet</span>
            </h1>

            <div class="section__media">
              <div class="section__media__back">
                <img src="./img-big.jpg" alt="Image" />
              </div>

              <div class="section__media__front front-1">
                <img src="./img-big.jpg" alt="Image" />
              </div>
              <div class="section__media__front front-2">
                <img src="./img-big.jpg" alt="Image" />
              </div>
              <div class="section__media__front front-3">
                <img src="./img-big.jpg" alt="Image" />
              </div>
              <div class="section__media__front front-4">
                <img src="./img-big.jpg" alt="Image" />
              </div>
              <div class="section__media__front front-5">
                <img src="./img-big.jpg" alt="Image" />
              </div>
              <div class="section__media__front front-6">
                <img src="./img-big.jpg" alt="Image" />
              </div>
            </div>

            <div class="section__images">
              <img src="./img-1.webp" alt="Image" />
              <img src="./img-2.webp" alt="Image" />
              <img src="./img-3.webp" alt="Image" />
              <img src="./img-4.webp" alt="Image" />
              <img src="./img-9.webp" alt="Image" />
              <img src="./img-6.webp" alt="Image" />
              <img src="./img-7.webp" alt="Image" />
              <img src="./img-8.webp" alt="Image" />
              <img src="./img-9.webp" alt="Image" />
              <img src="./img-10.webp" alt="Image" />
            </div>
          </div>
        </div>
      </div>
    </main>
    <script type="module" src="./src/main.js"></script>
  </body>
</html>
src/base.css
파일 저장

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

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

body {
  margin: 0;
  color: var(--color-text);
  background-color: var(--color-bg);
  font-family: 'area-normal', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html,
body {
  max-width: 100vw;
  overflow-x: hidden;
}

body {
  margin: 0;
}

@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);
  font-weight: 600;
  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 {
  display: grid;
  z-index: 1000;
  grid-row-gap: 1rem;
  grid-column-gap: 2rem;
  pointer-events: none;
  justify-items: start;
  align-content: start;
  padding: var(--page-padding);
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  grid-template-columns: auto auto auto 1fr;
  grid-template-rows: auto auto;
  grid-template-areas:
    'title title title sponsor'
    'back github archive sponsor';

  #cdawrap {
    max-width: 400px;
    align-self: start;
    text-align: right;
  }

  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;
  }
}
함께 쓰는 파일 7개 보기
src/main.js
파일 저장

import "./style.css"

import { preloadImages } from './utils.js'

import gsap from "gsap"
import { ScrollTrigger } from "gsap/ScrollTrigger"
import { ScrollSmoother } from "gsap/ScrollSmoother"

gsap.registerPlugin(ScrollTrigger, ScrollSmoother)

class Animation {
  constructor() {
    this.dom = document.querySelector(".section")
    this.frontImages = this.dom.querySelectorAll(".section__media__front")
    this.smallImages = this.dom.querySelectorAll(".section__images img")
  }

  init() {
    this.timeline = gsap.timeline({
      scrollTrigger: {
        trigger: this.dom,
        start: "top top",
        end: "bottom top",
        scrub: true,
        pin: true,
        onUpdate: (self) => {
          const easedProgress = gsap.parseEase("power1.inOut")(self.progress)
          this.dom.style.setProperty("--progress", easedProgress)
        }
      }
    })

    this.animate()
  }

  animate() {
    gsap.set(this.smallImages, {
      transformStyle: "preserve-3d",
      backfaceVisibility: "hidden",
      force3D: true
    })

    this.timeline.to(this.smallImages, {
      z: "100vh",
      duration: 1,
      ease: "power1.inOut",
      stagger: {
        amount: 0.2,
        from: "center"
      }
    })

    this.timeline.to(this.frontImages, {
      scale: 1,
      duration: 1,
      ease: "power1.inOut",
      delay: .1,
    }, 0.6)

    this.timeline.to(this.frontImages, {
      duration: 1,
      filter: "blur(0px)",
      ease: "power1.inOut",
      delay: .4,
      stagger: {
        amount: 0.2,
        from: "end"
      }
    }, 0.6)
  }
}

const scroller = ScrollSmoother.create({
  wrapper: ".wrapper",
  content: ".content",
  smooth: 1.5,
  effects: true,
  normalizeScroll: true
})

const animation = new Animation()

preloadImages('.wrapper img').then(() => {
  animation.init()
  document.body.classList.remove('loading')
})
src/style.css
파일 저장

.section {
  position: relative;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;

  --progress: 0;

  .section__media {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;

    transform: scale(var(--progress));

    .section__media__front,
    .section__media__back {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
    }

    .section__media__front {
      filter: blur(2px);

      img {
        mask-image: url(./mask.png);
        mask-position: 50% 50%;
        mask-size: cover;
      }
    }

    .front-1 {
      transform: scale(1);
    }

    .front-2 {
      transform: scale(0.85);
    }

    .front-3 {
      transform: scale(0.6);
    }

    .front-4 {
      transform: scale(0.45);
    }

    .front-5 {
      transform: scale(0.3);
    }

    .front-6 {
      transform: scale(0.15);
    }

    img {
      position: absolute;
      width: 100%;
      height: 100%;
      object-fit: cover;
      object-position: center;
    }
  }

  h1 {
    font-size: 3vw;
    font-weight: normal;
    transform: translateY(-15%);
    font-weight: 600;
    display: flex;

    span {
      display: inline-block;
    }

    .left {
      transform: translate3d(calc(var(--progress) * (-66vw + 100%) - 0.5vw), 0, 0);
    }

    .right {
      transform: translate3d(calc(var(--progress) * (66vw - 100%)), 0, 0);
    }

    @media (max-width: 768px) {
      font-size: 9vw;

      .left {
        transform: translate3d(calc(var(--progress) * (-100vw + 100%) - 0.5vw), 0, 0);
      }

      .right {
        transform: translate3d(calc(var(--progress) * (100vw - 100%)), 0, 0);
      }
    }
  }
}

.section__images {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  perspective: 100vh;

  img {
    position: absolute;
    width: 10vw;

    @media (max-width: 768px) {
      width: 20vw;
    }

    &:nth-of-type(1) {
      top: 15vw;
      left: -3vw;
    }

    &:nth-of-type(2) {
      top: 5vw;
      left: 20vw;
    }

    &:nth-of-type(3) {
      top: 8vw;
      left: 26.5vw;

      @media (max-width: 768px) {
        top: 30vw;
        left: 30vw;
      }
    }

    &:nth-of-type(4) {
      top: 18vw;
      right: 18vw;

      @media (max-width: 768px) {
        right: 15vw;
        top: 30vw;
      }
    }

    &:nth-of-type(5) {
      top: 5vw;
      right: 10vw;

      @media (max-width: 768px) {
        top: 10vw;
        right: 5vw;
      }
    }

    &:nth-of-type(6) {
      bottom: 5vw;
      left: 10vw;

      @media (max-width: 768px) {
        left: 5vw;
      }
    }

    &:nth-of-type(7) {
      bottom: 8vw;
      left: 22.5vw;

      @media (max-width: 768px) {
        left: 10vw;
        bottom: 27.5vw;
      }
    }

    &:nth-of-type(8) {
      bottom: 3vw;
      left: 45vw;

      @media (max-width: 768px) {
        bottom: 10vw;
        left: 35vw;
      }
    }

    &:nth-of-type(9) {
      bottom: 5vw;
      right: 15vw;

      @media (max-width: 768px) {
        bottom: 5vw;
      }
    }

    &:nth-of-type(10) {
      bottom: 9vw;
      right: 7vw;

      @media (max-width: 768px) {
        right: 3vw;
        bottom: 22vw;
      }
    }
  }
}
src/utils.js
파일 저장

import imagesLoaded from 'imagesloaded'

/**
 * Preloads images specified by the CSS selector.
 * @function
 * @param {string} [selector='img'] - CSS selector for target images.
 * @returns {Promise} - Resolves when all specified images are loaded.
 */
const preloadImages = (selector = 'img') => {
  return new Promise((resolve) => {
    // The imagesLoaded library is used to ensure all images (including backgrounds) are fully loaded.
    imagesLoaded(document.querySelectorAll(selector), { background: true }, resolve);
  });
};

// Exporting utility functions for use in other modules.
export {
  preloadImages
};


vite.config.js
파일 저장

// vite.config.js
import { defineConfig } from 'vite';

export default defineConfig({
  base: './',
});
Original author attribution실행 안내·자료
파일 저장

Building a Layered Zoom Scroll Effect with GSAP ScrollSmoother and ScrollTrigger
Original author: Joffrey Spitzer
Published by Codrops. Copyright (c) 2026 Codrops.
License: MIT, pursuant to the publisher's downloadable-demo grant.
Keep CODROPS-MIT-2026.txt and the original project notices with copies.
Third-party media exceptions and credits are recorded separately in the source inventory.
Media credits and license evidence실행 안내·자료
파일 저장

README.md
## Credits

- An original idea by [Louis Paquet](https://louispaquet.com/), [Adrien Vanderpotte](https://avdp.xyz/), [Kim Levan](https://x.com/kimlevan), [KOKI-KIKO](https://www.koki-kiko.com/)
- Images Free for Personal and Business use from [pexels](https://www.pexels.com)


## License

[MIT](LICENSE)
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


ev-emitter@2.1.2 — LICENSE.md
Copyright (c) 2016-2021 [David DeSandro](https://desandro.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.


imagesloaded@5.0.0 — LICENSE.md
Copyright (c) 2011-2022 [David DeSandro](https://desandro.com) and [contributors](https://github.com/desandro/imagesloaded/graphs/contributors)

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.