
Kim JeongHyeonFrontend Focused Fullstack Developer
Web Animation API의 기본 사용법부터 ScrollTimeline, GSAP과의 비교까지.
CSS 애니메이션과 JavaScript의 장점을 결합한 Web Animation API(WAAPI)를 소개합니다.
const element = document.querySelector(".box");
const animation = element.animate(
[
{ transform: "translateX(0)", opacity: 1 },
{ transform: "translateX(300px)", opacity: 0.5 },
],
{
duration: 1000,
easing: "ease-in-out",
fill: "forwards",
}
);// CSS: 선언적 → 제어 어려움
// WAAPI: 명령적 → 세밀한 제어 가능
animation.pause();
animation.reverse();
animation.playbackRate = 2; // 2배속
animation.currentTime = 500; // 특정 시점으로 이동
// 완료 감지
animation.finished.then(() => {
console.log("Animation complete!");
});더 복잡한 애니메이션을 미리 정의할 수 있습니다:
const effect = new KeyframeEffect(
element,
[
{ transform: "scale(1)", offset: 0 },
{ transform: "scale(1.2)", offset: 0.3 },
{ transform: "scale(0.8)", offset: 0.7 },
{ transform: "scale(1)", offset: 1 },
],
{ duration: 800, iterations: Infinity }
);
const animation = new Animation(effect, document.timeline);
animation.play();const timeline = new ScrollTimeline({
source: document.documentElement,
axis: "block",
});
element.animate(
{ opacity: [0, 1], transform: ["translateY(50px)", "translateY(0)"] },
{ timeline, rangeStart: "entry 0%", rangeEnd: "entry 100%" }
);| 기준 | WAAPI | GSAP |
|---|---|---|
| 번들 크기 | 0 (네이티브) | ~30KB |
| 성능 | 최적 (브라우저 네이티브) | 우수 |
| Timeline | ScrollTimeline | ScrollTrigger |
| 호환성 | 모던 브라우저 | IE11+ |
| 기능 | 기본 | 매우 풍부 |
단순한 애니메이션은 WAAPI, 복잡한 시퀀스는 GSAP이 적합합니다.