GSAP 원본
Pinned panels with overscroll
스크롤 · MIT (public Pen panels); GSAP Standard No Charge License
갤러리 안에서는 화면을 벗어나거나 움직임을 멈추면 예제도 닫힙니다. 다시 재생할 때는 처음부터 시작해요.
저장한 HTML에서는 갤러리의 재생 설정이 적용되지 않아요.
SOURCE FILES
원본 코드 읽기
수집한 원본 소스와 실행 안내를 함께 제공합니다. 실행 HTML에는 미리보기를 위한 실행 환경이 들어 있습니다.
vendor/gsap-previews/sources/gsap-ea2ae49fbb30/index.html
<div class="slides-wrapper">
<section class="section section-1">
<div class="section-content">
<div class="section-inner">
<h1>Section 1</h1>
<img class="image" src="https://assets.codepen.io/16327/portrait-image-3.jpg" alt="" />
</div>
</div>
</section>
<section class="section section-2">
<div class="section-content">
<div class="section-inner">
<h1>Section 2</h1>
<p>This section is long with text content and needs to be scrollable within before the next slide comes in.</p>
<p>This section is long with text content and needs to be scrollable within before the next slide comes in.</p>
<p>This section is long with text content and needs to be scrollable within before the next slide comes in.</p>
<p>This section is long with text content and needs to be scrollable within before the next slide comes in.</p>
<p>This section is long with text content and needs to be scrollable within before the next slide comes in.</p>
<p>This section is long with text content and needs to be scrollable within before the next slide comes in.</p>
<p>This section is long with text content and needs to be scrollable within before the next slide comes in.</p>
<p>This section is long with text content and needs to be scrollable within before the next slide comes in.</p>
<p>This section is long with text content and needs to be scrollable within before the next slide comes in.</p>
<p>This section is long with text content and needs to be scrollable within before the next slide comes in.</p>
<p>This section is long with text content and needs to be scrollable within before the next slide comes in.</p>
<p>This is the end...</p>
</div>
</div>
</section>
<section class="section section-3">
<div class="section-content">
<div class="section-inner">
<h1>Section 3</h1>
<img class="image" src="https://assets.codepen.io/16327/portrait-image-4.jpg" alt="" />
</div>
</div>
</section>
<section class="section section-4">
<div class="section-content">
<div class="section-inner">
<h1>Section 4</h1>
<img class="image" src="https://assets.codepen.io/16327/portrait-image-2.jpg" alt="" />
</div>
</div>
</section>
</div>vendor/gsap-previews/sources/gsap-ea2ae49fbb30/style.css
html,
body {
margin: 0;
height: 100%;
-webkit-overflow-scrolling: touch;
overflow-scrolling: touch;
}
body {
overflow-x: hidden;
overflow-y: scroll;
}
.nav {
width: 100%;
height: 60px;
position: fixed;
top: 0;
z-index: 999;
display: flex;
color: #fff;
background: #000;
justify-content: space-between;
}
.nav-links {
display: flex;
}
.slides-wrapper {
margin-top: 63px;
}
.image {
width: 50%;
aspect-ratio: 1/1;
object-fit: cover;
margin-top: 2.5rem;
}
.section {
width: 100%;
height: calc(100vh - 64px);
display: flex;
justify-content: center;
font-weight: 600;
font-size: 1.5em;
text-align: center;
position: relative;
box-sizing: border-box;
background: var(--color-grey);
overflow: hidden;
border-radius: 10px;
}
p {
max-width: 40ch;
padding: 2rem
}
.section-inner {
height: 100%;
overflow: hidden;
display: flex;
flex-direction: column;
align-items: center
}
.section-2 .section-inner {
height: auto;
padding-bottom: 20vh;
}
.section-2 {
background: var(--color-scroll-pink-lt);
color: var(--dark);
}
.section-1 {
background: var(--light);
color: var(--dark);
}
.section-4 {
background: var(--color-text-purple);
color: var(--dark);
}
.height {
border: dashed 2px grey;
padding: 1rem;
padding-bottom: 5rem;
}
.section h1 {
font-size: max(4rem, min(12vw + 1rem, 16rem));
font-weight: 600;
margin: 0 auto;
}
img {
border-radius: 8px;
}
함께 쓰는 파일 4개 보기
vendor/gsap-previews/sources/gsap-ea2ae49fbb30/script.js
gsap.registerPlugin(ScrollTrigger);
var panels = gsap.utils.toArray(".section");
panels.pop();
panels.forEach((panel, i) => {
// Get the element holding the content inside the panel
let innerpanel = panel.querySelector(".section-inner");
// Get the Height of the content inside the panel
let panelHeight = innerpanel.offsetHeight;
console.log(panelHeight)
// Get the window height
let windowHeight = window.innerHeight;
let difference = panelHeight - windowHeight;
// ratio (between 0 and 1) representing the portion of the overall animation that's for the fake-scrolling. We know that the scale & fade should happen over the course of 1 windowHeight, so we can figure out the ratio based on how far we must fake-scroll
let fakeScrollRatio = difference > 0 ? (difference / (difference + windowHeight)) : 0;
// if we need to fake scroll (because the panel is taller than the window), add the appropriate amount of margin to the bottom so that the next element comes in at the proper time.
if (fakeScrollRatio) {
panel.style.marginBottom = panelHeight * fakeScrollRatio + "px";
}
let tl = gsap.timeline({
scrollTrigger:{
trigger: panel,
start: "bottom bottom",
end: () => fakeScrollRatio ? `+=${innerpanel.offsetHeight}` : "bottom top",
pinSpacing: false,
pin: true,
scrub: true
}
});
// fake scroll. We use 1 because that's what the rest of the timeline consists of (0.9 scale + 0.1 fade)
if (fakeScrollRatio) {
tl.to(innerpanel, {yPercent:-100, y: window.innerHeight, duration: 1 / (1 - fakeScrollRatio) - 1, ease: "none"});
}
tl.fromTo(panel, {scale:1, opacity:1}, {scale: 0.7, opacity: 0.5, duration: 0.9})
.to(panel, {opacity:0, duration: 0.1});
});
vendor/gsap-previews/sources/gsap-ea2ae49fbb30/adapters/host.css실행 안내·자료
/* StyleGallery host styles: independent replacement for unavailable shared Pen CSS. */
:root{--color-just-black:#111522;--color-surface-white:#f7f3ec;--color-surface75:#cfccc6;--color-surface50:#898e9f;--color-surface25:#414859;--color-shockingly-green:#95efd2;--color-lt-green:#b5f4da;--color-pink:#fbadce;--color-purple:#897dff;--color-lilac:#b5a1ff;--color-orangey:#ffd28c;--color-blue:#75d8ed;--color-ui-gradient:linear-gradient(135deg,#fbadce,#897dff);--color-ui-gradient-background:linear-gradient(135deg,#fbadce,#897dff);--color-text-gradient:linear-gradient(135deg,#fbadce,#897dff);--gradient-summer-fair:linear-gradient(135deg,#ffd28c,#fbadce);--gradient-lipstick:linear-gradient(135deg,#fbadce,#fc7f8e);--gradient-macha:linear-gradient(135deg,#b5f4da,#75d8ed);--color-grey:#898e9f;--color-grey-dark:#414859;--color-scroll-pink-lt:#fbadce;--color-text-purple:#b5a1ff;--surface50:#898e9f;--light:#f7f3ec;--dark:#111522;--mid:#898e9f}
*{box-sizing:border-box}body{background:#111522;color:#f7f3ec;font-family:system-ui,sans-serif;margin:0;min-height:100vh;width:100%}button,input{font:inherit}button,.button{background:#111522;border:1px solid #898e9f;border-radius:.55rem;color:#f7f3ec;cursor:pointer;padding:.65rem 1rem}button:focus-visible,a:focus-visible,input:focus-visible{outline:3px solid #95efd2;outline-offset:4px}h1,h2,h3,h4{line-height:1.15}h4{font-weight:500}code{font-family:ui-monospace,monospace}.heading-l{font-size:clamp(2rem,6vw,5rem)}.heading-text{font-size:clamp(1.5rem,4vw,3rem)}.box{background:#95efd2;border-radius:14px;height:clamp(38px,12vw,80px);width:clamp(38px,12vw,80px)}.green{background:#95efd2}.purple{background:#897dff}.orange{background:#ffd28c}.gradient-pink{background:linear-gradient(140deg,#fbadce,#fc7f8e)}.gradient-purple{background:linear-gradient(140deg,#b5a1ff,#537ff7)}.center{align-items:center;display:flex;justify-content:center}.text-center{text-align:center}.panel{min-height:100vh;width:100%}.flair:not(img){background-image:url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNDgiIGhlaWdodD0iMjQ4IiB2aWV3Qm94PSIwIDAgMjQ4IDI0OCI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJnIiB4Mj0iMSIgeTI9IjEiPjxzdG9wIHN0b3AtY29sb3I9IiNiNWExZmYiLz48c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiM3NWQ4ZWQiLz48L2xpbmVhckdyYWRpZW50PjwvZGVmcz48ZyBmaWxsPSJ1cmwoI2cpIj48cGF0aCBkPSJNODcgMjBoNzR2NjdoNjd2NzRoLTY3djY3SDg3di02N0gyMFY4N2g2N1oiLz48L2c+PC9zdmc+");background-position:center;background-repeat:no-repeat;background-size:contain;height:80px;width:80px}.flair--3:not(img){background-image:url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNDgiIGhlaWdodD0iMjQ4IiB2aWV3Qm94PSIwIDAgMjQ4IDI0OCI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJnIiB4Mj0iMSIgeTI9IjEiPjxzdG9wIHN0b3AtY29sb3I9IiM5NWVmZDIiLz48c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiM1MzdmZjciLz48L2xpbmVhckdyYWRpZW50PjwvZGVmcz48ZyBmaWxsPSJ1cmwoI2cpIj48Y2lyY2xlIGN4PSIxMjQiIGN5PSIxMjQiIHI9Ijg4IiBmaWxsPSJub25lIiBzdHJva2U9InVybCgjZykiIHN0cm9rZS13aWR0aD0iNDgiLz48Y2lyY2xlIGN4PSIxODMiIGN5PSI2MCIgcj0iMjMiIGZpbGw9IiNmNmYzZWIiLz48L2c+PC9zdmc+")}.braces{font-size:1rem}img{max-width:100%}
/* External font programs are omitted; preserve readable fallback typography. */
body,button,input,h1,h2,h3,h4,p,span,div{font-family:inherit}body{font-family:system-ui,sans-serif}code,pre{font-family:ui-monospace,monospace}
vendor/gsap-previews/sources/gsap-ea2ae49fbb30/adapters/script.js실행 안내·자료
window.__STYLEGALLERY_ASSETS__={};
gsap.registerPlugin(ScrollTrigger);
var panels = gsap.utils.toArray(".section");
panels.pop();
panels.forEach((panel, i) => {
let innerpanel = panel.querySelector(".section-inner");
let panelHeight = innerpanel.offsetHeight;
console.log(panelHeight);
let windowHeight = window.innerHeight;
let difference = panelHeight - windowHeight;
let fakeScrollRatio = difference > 0 ? difference / (difference + windowHeight) : 0;
if (fakeScrollRatio) {
panel.style.marginBottom = panelHeight * fakeScrollRatio + "px";
}
let tl = gsap.timeline({
scrollTrigger: {
trigger: panel,
start: "bottom bottom",
end: () => fakeScrollRatio ? `+=${innerpanel.offsetHeight}` : "bottom top",
pinSpacing: false,
pin: true,
scrub: true
}
});
if (fakeScrollRatio) {
tl.to(innerpanel, { yPercent: -100, y: window.innerHeight, duration: 1 / (1 - fakeScrollRatio) - 1, ease: "none" });
}
tl.fromTo(panel, { scale: 1, opacity: 1 }, { scale: 0.7, opacity: 0.5, duration: 0.9 }).to(panel, { opacity: 0, duration: 0.1 });
});
LICENSE실행 안내·자료
<!--
Copyright (c) 2021 - GreenSock - https://codepen.io/GreenSock/pen/bGRdvMy
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.
-->
GSAP 3.15.0
Copyright 2026, GreenSock. All rights reserved.
Subject to the Standard No Charge License: https://gsap.com/standard-license.
The full notice in each original GSAP library file is preserved.
StyleGallery host adapter and replacement SVG subjects: locally authored.
BEHIND THE EXAMPLE
이 장면을 만드는 원리
내용 이동과 장면 퇴장의 시간 배분
장면 효과가 긴 콘텐츠 접근을 가리지 않도록 내용 길이를 먼저 계산합니다.
- 이 예제에서는
- inner의 초과 높이로 fakeScrollRatio와 여백을 계산합니다. 긴 패널에서는 inner를 위로 이동하는 구간을 먼저 넣고 패널의 scale·opacity 퇴장을 이어 붙입니다. 최초 ratio와 margin은 resize에서 다시 구하지 않으므로 end 함수가 새 높이를 읽는 것만으로 전체 크기 대응이 보장되지는 않습니다.
