HyperFrames용 Web Animations API
HyperFrames는 waapi 런타임 어댑터를 통해 Web Animations API 애니메이션을 탐색할 수 있습니다. WAAPI는 GSAP 의존성 없이 네이티브 브라우저 키프레임과 JavaScript로 생성된 타이밍을 사용하려는 경우 유용합니다.
계약
- 컴포지션 초기화 중에 애니메이션을 동기적으로 생성하십시오.
- 유한한
duration과iterations으로element.animate(...)를 사용하십시오. - 탐색된 상태가 지속되도록
fill: "both"를 사용하십시오. - 생성 후 애니메이션을 일시 중지하거나, 첫 탐색 시 어댑터가 일시 중지하도록 두십시오.
- 렌더링에 중요한 상태에 대해 콜백과 프로미스를 사용하지 마십시오.
어댑터는 document.getAnimations()를 호출하고, 각 애니메이션의 currentTime을 HyperFrames 시간(밀리초)으로 설정한 다음 일시 중지합니다.
기본 패턴
<div id="orb" class="clip orb" data-start="2" data-duration="3" data-track-index="2"></div>
<script>
const orb = document.getElementById("orb");
const animation = orb.animate(
[
{ transform: "translate3d(-160px, 0, 0) scale(0.8)", opacity: 0 },
{ transform: "translate3d(0, 0, 0) scale(1)", opacity: 1, offset: 0.35 },
{ transform: "translate3d(120px, 0, 0) scale(1.08)", opacity: 1 },
],
{
duration: 3000,
delay: 2000,
easing: "cubic-bezier(0.2, 0, 0, 1)",
fill: "both",
iterations: 1,
},
);
animation.pause();
</script>
스태거 패턴
document.querySelectorAll(".token").forEach((token, index) => {
const animation = token.animate(
[
{ transform: "translateY(24px)", opacity: 0 },
{ transform: "translateY(0)", opacity: 1 },
],
{
duration: 620,
delay: index * 80,
easing: "cubic-bezier(0.2, 0, 0, 1)",
fill: "both",
iterations: 1,
},
);
animation.pause();
});
좋은 사용 예
- CSS 키프레임이 너무 경직되고 GSAP이 필요하지 않은 경량 DOM 모션.
- 구조화된 데이터에서 생성된 애니메이션.
- 키프레임, 지연 시간, 오프셋으로 표현할 수 있는 간단한 타임라인.
피해야 할 것
- 무한
iterations. - 렌더링에 중요한 DOM을 변경하기 위해
animation.finished에 의존하는 것. requestAnimationFrame, 타이머 또는performance.now()로 별도의 클록을 실행하는 것.- 변형(transform)과 불투명도(opacity)로 모션을 표현할 수 있는데 레이아웃 속성을 애니메이션하는 것.
- 클립 로컬 시작 시간이 자동이라고 가정하는 것. WAAPI 어댑터는 문서 수준의 애니메이션 시간을 탐색합니다.
delay로 클립 오프셋을 모델링하거나, HyperFrames 타이밍에 의해 가시성이 제어되는 요소에 애니메이션을 만드십시오.
검증
WAAPI 컴포지션을 편집한 후:
npx hyperframes lint
npx hyperframes validate
크레딧 및 참고 자료
- HyperFrames 어댑터 소스:
packages/core/src/runtime/adapters/waapi.ts. - MDN Web Animations API 가이드: https://developer.mozilla.org/docs/Web/API/Web_Animations_API/Using_the_Web_Animations_API
- MDN
Animation.currentTime: https://developer.mozilla.org/en-US/docs/Web/API/Animation/currentTime