Scroll Pin
scrollTrigger: { pin: true, scrub: 1 } pins the element to the viewport while the page scrolls past. The element stays fixed until the scroll distance defined by end is exhausted. The pinned element’s content can animate independently via tweens on the same timeline.
scrollTrigger: { pin: true, scrub: 1 }이 페이지가 스크롤되는 동안 요소를 뷰포트에 고정합니다. end로 정의한 스크롤 거리를 소진할 때까지 요소가 고정됩니다. 고정된 요소의 콘텐츠는 동일 타임라인의 트윈으로 독립적으로 애니메이션됩니다.
Source Code script.js
gsap.registerPlugin(ScrollTrigger);
const track = document.querySelector('#hTrack');
gsap.to(track, {
x: () => -(track.scrollWidth - window.innerWidth),
ease: 'none',
scrollTrigger: {
trigger: '.pin-wrap',
pin: true,
scrub: 1,
end: () => '+=' + (track.scrollWidth - window.innerWidth),
invalidateOnRefresh: true,
},
});