|
| 1 | +import { gsap } from 'gsap'; |
| 2 | +import { ScrollTrigger } from 'gsap/ScrollTrigger'; |
| 3 | + |
| 4 | +let pluginsRegistered = false; |
| 5 | + |
| 6 | +interface AnimateOptions { |
| 7 | + trigger: HTMLElement; // 스크롤 트리거 기준 요소 |
| 8 | + targets: gsap.TweenTarget; // 애니메이션 대상 |
| 9 | + stagger?: number; // 순차 재생 간격 |
| 10 | + start?: string; // 스크롤 시작 지점 |
| 11 | + yOffset?: number; // y축 이동 거리 |
| 12 | +} |
| 13 | + |
| 14 | +/* Fade Up 함수 */ |
| 15 | +const animateFadeUp = ({ |
| 16 | + trigger, |
| 17 | + targets, |
| 18 | + stagger = 0, |
| 19 | + start = 'top center-=50', |
| 20 | + yOffset = 24, |
| 21 | +}: AnimateOptions) => { |
| 22 | + if (!pluginsRegistered) { |
| 23 | + gsap.registerPlugin(ScrollTrigger); |
| 24 | + pluginsRegistered = true; |
| 25 | + } |
| 26 | + |
| 27 | + const ctx = gsap.context(() => { |
| 28 | + gsap.fromTo( |
| 29 | + targets, |
| 30 | + { opacity: 0, y: yOffset }, |
| 31 | + { |
| 32 | + opacity: 1, |
| 33 | + y: 0, |
| 34 | + duration: 0.6, |
| 35 | + ease: 'power2.out', |
| 36 | + stagger: stagger, |
| 37 | + scrollTrigger: { |
| 38 | + trigger: trigger, |
| 39 | + start: start, |
| 40 | + toggleActions: 'play none none reverse', |
| 41 | + // markers: true, |
| 42 | + }, |
| 43 | + } |
| 44 | + ); |
| 45 | + }); |
| 46 | + |
| 47 | + return () => ctx.revert(); |
| 48 | +}; |
| 49 | + |
| 50 | +/* --- 1. Hero Section --- */ |
| 51 | +export type HeroSectionRefs = { |
| 52 | + titleEl: HTMLHeadingElement; |
| 53 | + subTextEl: HTMLDivElement; |
| 54 | +}; |
| 55 | + |
| 56 | +export const initHeroSectionAnimation = ({ |
| 57 | + titleEl, |
| 58 | + subTextEl, |
| 59 | +}: HeroSectionRefs) => { |
| 60 | + return animateFadeUp({ |
| 61 | + trigger: titleEl, |
| 62 | + targets: subTextEl, |
| 63 | + start: 'top center-=150', |
| 64 | + yOffset: 40, |
| 65 | + }); |
| 66 | +}; |
| 67 | + |
| 68 | +/* --- 2. Feature List Section --- */ |
| 69 | +export type FeatureListRefs = { |
| 70 | + titleEl: HTMLHeadingElement; |
| 71 | + subTextEl: HTMLDivElement; |
| 72 | + cardsContainerEl: HTMLDivElement; |
| 73 | +}; |
| 74 | + |
| 75 | +export const initFeatureListAnimation = ({ |
| 76 | + titleEl, |
| 77 | + subTextEl, |
| 78 | + cardsContainerEl, |
| 79 | +}: FeatureListRefs) => { |
| 80 | + const cards = Array.from(cardsContainerEl.children); |
| 81 | + |
| 82 | + return animateFadeUp({ |
| 83 | + trigger: titleEl, |
| 84 | + targets: [subTextEl, ...cards], |
| 85 | + stagger: 0.12, |
| 86 | + }); |
| 87 | +}; |
| 88 | + |
| 89 | +/* --- 3. Landing Preview Section --- */ |
| 90 | +export type LandingPreviewRefs = { |
| 91 | + titleEl: HTMLHeadingElement; |
| 92 | + contentContainerEl: HTMLDivElement; |
| 93 | +}; |
| 94 | + |
| 95 | +export const initLandingPreviewAnimation = ({ |
| 96 | + titleEl, |
| 97 | + contentContainerEl, |
| 98 | +}: LandingPreviewRefs) => { |
| 99 | + const items = contentContainerEl.querySelectorAll('.fc-item'); |
| 100 | + |
| 101 | + return animateFadeUp({ |
| 102 | + trigger: titleEl, |
| 103 | + targets: items, |
| 104 | + stagger: 0.2, |
| 105 | + }); |
| 106 | +}; |
0 commit comments