미리보기 안의 버튼·입력·포인터로 모션을 확인하세요. 실행 방식은 아래 활용 메모를 참고하세요.
실행용 통합 HTML · 공식 GSAP 3.15.0
<!doctype html>
<!-- Archived from GSAP Demo Hub / image-mask-on-scroll
Original editor: https://codepen.io/GreenSock/pen/oNjgEjm
HTML/CSS/JS source panels are preserved separately. Runtime GSAP: 3.15.0 official distribution. -->
<html lang="en" class=""><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Image Mask On Scroll</title>
<link rel="stylesheet" href="https://asset.wemashup.com/wp-content/uploads/wm-asset-library/gsap/shared/wvZQKQP.css">
<style>
body {
height: 300vh;
overflow-x: hidden;
}
h1,
h2 {
font-weight: 400;
max-width: none;
}
.comparisonSection {
position: relative;
padding-bottom: 56.25%; /* to maintain aspect ratio (responsive!) */
}
.comparisonImage {
width: 100%;
height: 100%;
}
.afterImage {
position: absolute;
overflow: hidden;
top: 0;
transform: translate(100%, 0px);
}
.afterImage img {
transform: translate(-100%, 0px);
}
.comparisonImage img {
width: 100%;
height: 100%;
position: absolute;
top: 0;
}
.panel {
display: flex;
align-items: center;
justify-content: center;
min-height: 90vh;
}
</style></head><body>
<section class="panel">
<h4 class="header-section">Scroll to see the before/after</h4>
</section>
<section class="comparisonSection">
<div class="comparisonImage beforeImage">
<img src="https://assets.codepen.io/16327/before.jpg" alt="before">
</div>
<div class="comparisonImage afterImage">
<img src="https://assets.codepen.io/16327/after.jpg" alt="after">
</div>
</section>
<script src="https://asset.wemashup.com/wp-content/uploads/wm-asset-library/gsap/shared/gsap-3.15.0-gsap.min.js"></script>
<script src="https://asset.wemashup.com/wp-content/uploads/wm-asset-library/gsap/shared/gsap-3.15.0-ScrollTrigger.min.js"></script>
<script>
gsap.utils.toArray(".comparisonSection").forEach(section => {
let tl = gsap.timeline({
scrollTrigger: {
trigger: section,
start: "center center",
// makes the height of the scrolling (while pinning) match the width, thus the speed remains constant (vertical/horizontal)
end: () => "+=" + section.offsetWidth,
scrub: true,
pin: true,
anticipatePin: 1
},
defaults: {ease: "none"}
});
// animate the container one way...
tl.fromTo(section.querySelector(".afterImage"), { xPercent: 100, x: 0}, {xPercent: 0})
// ...and the image the opposite way (at the same time)
.fromTo(section.querySelector(".afterImage img"), {xPercent: -100, x: 0}, {xPercent: 0}, 0);
});
</script>
</body></html>
원본 HTML
<section class="panel">
<h4 class="header-section">Scroll to see the before/after</h4>
</section>
<section class="comparisonSection">
<div class="comparisonImage beforeImage">
<img src="https://assets.codepen.io/16327/before.jpg" alt="before">
</div>
<div class="comparisonImage afterImage">
<img src="https://assets.codepen.io/16327/after.jpg" alt="after">
</div>
</section>
원본 CSS
body {
height: 300vh;
overflow-x: hidden;
}
h1,
h2 {
font-weight: 400;
max-width: none;
}
.comparisonSection {
position: relative;
padding-bottom: 56.25%; /* to maintain aspect ratio (responsive!) */
}
.comparisonImage {
width: 100%;
height: 100%;
}
.afterImage {
position: absolute;
overflow: hidden;
top: 0;
transform: translate(100%, 0px);
}
.afterImage img {
transform: translate(-100%, 0px);
}
.comparisonImage img {
width: 100%;
height: 100%;
position: absolute;
top: 0;
}
.panel {
display: flex;
align-items: center;
justify-content: center;
min-height: 90vh;
}
원본 JavaScript
gsap.utils.toArray(".comparisonSection").forEach(section => {
let tl = gsap.timeline({
scrollTrigger: {
trigger: section,
start: "center center",
// makes the height of the scrolling (while pinning) match the width, thus the speed remains constant (vertical/horizontal)
end: () => "+=" + section.offsetWidth,
scrub: true,
pin: true,
anticipatePin: 1
},
defaults: {ease: "none"}
});
// animate the container one way...
tl.fromTo(section.querySelector(".afterImage"), { xPercent: 100, x: 0}, {xPercent: 0})
// ...and the image the opposite way (at the same time)
.fromTo(section.querySelector(".afterImage img"), {xPercent: -100, x: 0}, {xPercent: 0}, 0);
});
검증·권리 정보
- 실행 검증
- 데스크톱 실행 확인
- 검증 수준
- 샘플 실행
- 권리 확인
- 확인 필요
스크롤에 따라 이미지의 마스크와 크기를 변화시킵니다.
Chromium 153 · 데스크톱 1280×900 · 격리 iframe에서 스크롤 입력과 화면 변화 확인. 모바일·프로젝트 적용은 미검증.
원본 패널과 통합 실행 파일은 분리해 보관했습니다. 원본의 구형 전용 라이브러리 대신 통합 실행은 공식 GSAP 3.15.0을 사용합니다.
보관·활용 메모
GSAP Demo Hub의 공개 예제입니다. 원본 HTML·CSS·JavaScript와 설정, 시연 파일을 함께 보관했습니다. 통합 HTML은 공통 스타일과 실행 의존성을 연결한 파일이며 SCSS는 원본 컴파일 결과를 사용합니다.
구형 CodePen 전용 의존성을 그대로 배포하지 않고, 통합 실행에는 공식 GSAP 3.15.0을 연결했습니다. 원본 패널과 원본 설정은 ZIP에 별도로 보존되어 있습니다. 예제의 이미지·폰트 등 외부 소재 요청은 유지됩니다.
보관일 2026-10-26 · 원본 코드·작성자·설정 정보를 보존했습니다. 실제 프로젝트에서 코드와 이미지·폰트의 사용 조건을 확인하세요.