waapi
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWeb Animations API for HyperFrames
适用于HyperFrames的Web Animations API
HyperFrames can seek Web Animations API animations through its runtime adapter. WAAPI is useful when you want native browser keyframes with JavaScript-created timing and no GSAP dependency.
waapiHyperFrames可以通过其运行时适配器来定位Web Animations API动画。当你想要使用原生浏览器关键帧,同时用JavaScript定义时序且不依赖GSAP时,WAAPI会非常实用。
waapiContract
约定
- Create animations synchronously during composition initialization.
- Use with finite
element.animate(...)andduration.iterations - Use so seeked states persist.
fill: "both" - Pause animations after creation or let the adapter pause them on first seek.
- Avoid callbacks and promises for render-critical state.
The adapter calls , sets each animation's to HyperFrames time in milliseconds, then pauses it.
document.getAnimations()currentTime- 在合成初始化阶段同步创建动画。
- 使用时设置有限的
element.animate(...)和duration。iterations - 使用以确保定位后的状态得以保留。
fill: "both" - 创建动画后暂停,或让适配器在首次定位时自动暂停。
- 避免使用回调和Promise处理渲染关键状态。
适配器会调用,将每个动画的设置为HyperFrames的时间(以毫秒为单位),然后暂停动画。
document.getAnimations()currentTimeBasic Pattern
基础模式
html
<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>html
<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>Stagger Pattern
stagger模式
js
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();
});js
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();
});Good Uses
适用场景
- Lightweight DOM motion where CSS keyframes are too rigid and GSAP is unnecessary.
- Generated animations from structured data.
- Simple timelines that can be represented as keyframes, delays, and offsets.
- 轻量级DOM动效:CSS关键帧过于僵化,且无需依赖GSAP时。
- 从结构化数据生成动画。
- 可通过关键帧、延迟和偏移量表示的简单时间线。
Avoid
注意避免
- Infinite .
iterations - Depending on to mutate render-critical DOM.
animation.finished - Running separate clocks with , timers, or
requestAnimationFrame.performance.now() - Animating layout properties when transforms and opacity can express the motion.
- Assuming clip-local start time is automatic. WAAPI adapter seeks document-level animation time; model clip offsets with or create the animation on an element whose visibility is controlled by HyperFrames timing.
delay
- 设置无限。
iterations - 依赖修改渲染关键DOM。
animation.finished - 使用、计时器或
requestAnimationFrame运行独立时钟。performance.now() - 当可以用transform和opacity实现动效时,仍对布局属性执行动画。
- 假设片段本地起始时间是自动设置的。WAAPI适配器会定位文档级动画时间;需用模拟片段偏移,或在受HyperFrames时序控制可见性的元素上创建动画。
delay
Validation
验证
After editing a WAAPI composition:
bash
npx hyperframes lint
npx hyperframes validate编辑WAAPI合成内容后:
bash
npx hyperframes lint
npx hyperframes validateCredits And References
致谢与参考
- HyperFrames adapter source: .
packages/core/src/runtime/adapters/waapi.ts - MDN Web Animations API guide: https://developer.mozilla.org/docs/Web/API/Web_Animations_API/Using_the_Web_Animations_API
- MDN : https://developer.mozilla.org/en-US/docs/Web/API/Animation/currentTime
Animation.currentTime
- 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 :https://developer.mozilla.org/en-US/docs/Web/API/Animation/currentTime
Animation.currentTime