스크롤 애니메이션 스킬 — 에이전시 / 프로덕트 품질
스크롤 애니메이션은 고예산 사이트가 그 가치를 증명하는 요소입니다. 제대로 구현되면 영화처럼 느껴지고, 잘못 구현되면 멀미를 유발합니다. 이 스킬은 올바르게 구현하는 방법을 제공합니다.
두 가지 접근법
| 사용 사례 | 도구 |
|---|---|
| React 컴포넌트, 단일 요소 | Framer Motion useScroll + useTransform |
| 복잡한 타임라인, 고정 시퀀스, 스크러빙 | GSAP ScrollTrigger |
Framer Motion: 스크롤 진입 시 페이드 + 슬라이드
import { motion, useInView } from 'framer-motion'
import { useRef } from 'react'
function RevealOnScroll({ children, delay = 0 }: { children: React.ReactNode; delay?: number }) {
const ref = useRef(null)
const isInView = useInView(ref, { once: true, margin: '-80px 0px' })
return (
<motion.div
ref={ref}
initial={{ opacity: 0, y: 32, filter: 'blur(6px)' }}
animate={isInView ? { opacity: 1, y: 0, filter: 'blur(0px)' } : {}}
transition={{ type: 'spring', stiffness: 200, damping: 24, delay }}
>
{children}
</motion.div>
)
}
Framer Motion: 스크롤 진행률 표시 막대
import { useScroll, useSpring, motion } from 'framer-motion'
function ScrollProgressBar() {
const { scrollYProgress } = useScroll()
const scaleX = useSpring(scrollYProgress, { stiffness: 100, damping: 30 })
return (
<motion.div
className="fixed top-0 left-0 right-0 h-[3px] bg-blue-500 origin-left z-50"
style={{ scaleX }}
/>
)
}
Framer Motion: 패럴랙스 히어로 이미지
import { useScroll, useTransform, motion } from 'framer-motion'
import { useRef } from 'react'
function ParallaxHero() {
const ref = useRef(null)
const { scrollYProgress } = useScroll({ target: ref, offset: ['start start', 'end start'] })
const y = useTransform(scrollYProgress, [0, 1], ['0%', '30%'])
const opacity = useTransform(scrollYProgress, [0, 0.6], [1, 0])
return (
<section ref={ref} className="relative h-screen overflow-hidden">
<motion.div className="absolute inset-0" style={{ y }}>
<img src="/hero.jpg" className="w-full h-full object-cover" alt="" />
</motion.div>
<motion.div className="relative z-10 flex items-center justify-center h-full" style={{ opacity }}>
<h1 className="text-white text-7xl font-bold">Hero Text</h1>
</motion.div>
</section>
)
}
GSAP ScrollTrigger: 고정 가로 스크롤 (Awwwards 스타일)
import { useEffect, useRef } from 'react'
import { gsap } from 'gsap'
import { ScrollTrigger } from 'gsap/ScrollTrigger'
gsap.registerPlugin(ScrollTrigger)
function HorizontalScrollSection() {
const sectionRef = useRef(null)
const trackRef = useRef(null)
useEffect(() => {
const track = trackRef.current
const totalWidth = track.scrollWidth - window.innerWidth
gsap.to(track, {
x: -totalWidth,
ease: 'none',
scrollTrigger: {
trigger: sectionRef.current,
start: 'top top',
end: `+=${totalWidth}`,
scrub: 1,
pin: true,
anticipatePin: 1,
}
})
return () => ScrollTrigger.getAll().forEach(t => t.kill())
}, [])
return (
<section ref={sectionRef} className="overflow-hidden">
<div ref={trackRef} className="flex w-max gap-8 p-16">
{panels.map((panel, i) => (
<div key={i} className="w-[80vw] h-screen flex-shrink-0 bg-gray-100 rounded-2xl" />
))}
</div>
</section>
)
}
GSAP ScrollTrigger: 텍스트 줄 단위 등장 효과
useEffect(() => {
const lines = gsap.utils.toArray('.reveal-line')
lines.forEach((line, i) => {
gsap.fromTo(line,
{ y: '100%', opacity: 0 },
{
y: '0%',
opacity: 1,
duration: 0.8,
ease: 'power3.out',
delay: i * 0.1,
scrollTrigger: {
trigger: line,
start: 'top 90%',
toggleActions: 'play none none none'
}
}
)
})
return () => ScrollTrigger.getAll().forEach(t => t.kill())
}, [])
스크롤 애니메이션 성능 규칙
transform과opacity만 애니메이션 처리 —top,left,width,height는 절대 사용 금지- 지속적으로 스크롤 애니메이션되는 요소에는
will-change: transform추가 useEffect의 반환 함수에서 항상 ScrollTrigger 인스턴스 정리- 부드러운 스크러빙을 위해
scrub: 1사용 (scrub: true대신) - 저사양 Android 기기에서 테스트 — 거기서 프레임 드롭이 발생하면 배포 시에도 문제 있음
useInView에서margin: '-80px 0px'를 사용하여 애니메이션이 너무 일찍 실행되지 않도록 방지
