Fixing Motion Performance

作者 ibelick587ea305b948無授權條款9.5K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫昨天更新

Audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects. Use when animations stutter, transitions jank, or reviewing CSS/JS animation performance.

AI 產生的概覽

審查並修正介面動畫效能問題,例如版面抖動、捲動連動動畫和模糊效果。

功能
提供依優先順序排列的規則集,用於審查和修正 CSS、WAAPI、Motion、rAF 與 GSAP 中的介面動畫效能問題。它會回報違規項目並引用具體程式碼片段,說明其影響,並提出具體的程式碼層級修正建議。也包含版面抖動、捲動連動動畫和測量批次處理的常見前後對照範例。
適用情境
適用於動畫卡頓或轉場不順暢時,或需要新增、修改、審查介面動畫效能時。適用於捲動連動動畫、捲動顯現、動畫版面、濾鏡、遮罩、漸層和 CSS 變數。
執行需求
無需指令碼或特殊工具,是僅含說明的參考規則,在現有動畫技術堆疊內套用。無需憑證或網路存取。

fixing-motion-performance

Fix animation performance issues.

how to use

  • /fixing-motion-performance Apply these constraints to any UI animation work in this conversation.

  • /fixing-motion-performance <file> Review the file against all rules below and report:

    • violations (quote the exact line or snippet)
    • why it matters (one short sentence)
    • a concrete fix (code-level suggestion)

Do not migrate animation libraries unless explicitly requested. Apply rules within the existing stack.

when to apply

Reference these guidelines when:

  • adding or changing UI animations (CSS, WAAPI, Motion, rAF, GSAP)
  • refactoring janky interactions or transitions
  • implementing scroll-linked motion or reveal-on-scroll
  • animating layout, filters, masks, gradients, or CSS variables
  • reviewing components that use will-change, transforms, or measurement

rendering steps glossary

  • composite: transform, opacity
  • paint: color, borders, gradients, masks, images, filters
  • layout: size, position, flow, grid, flex

rule categories by priority

prioritycategoryimpact
1never patternscritical
2choose the mechanismcritical
3measurementhigh
4scrollhigh
5paintmedium-high
6layersmedium
7blur and filtersmedium
8view transitionslow
9tool boundariescritical

quick reference

1. never patterns (critical)

  • do not interleave layout reads and writes in the same frame
  • do not animate layout continuously on large or meaningful surfaces
  • do not drive animation from scrollTop, scrollY, or scroll events
  • no requestAnimationFrame loops without a stop condition
  • do not mix multiple animation systems that each measure or mutate layout

2. choose the mechanism (critical)

  • default to transform and opacity for motion
  • use JS-driven animation only when interaction requires it
  • paint or layout animation is acceptable only on small, isolated surfaces
  • one-shot effects are acceptable more often than continuous motion
  • prefer downgrading technique over removing motion entirely

3. measurement (high)

  • measure once, then animate via transform or opacity
  • batch all DOM reads before writes
  • do not read layout repeatedly during an animation
  • prefer FLIP-style transitions for layout-like effects
  • prefer approaches that batch measurement and writes

4. scroll (high)

  • prefer Scroll or View Timelines for scroll-linked motion when available
  • use IntersectionObserver for visibility and pausing
  • do not poll scroll position for animation
  • pause or stop animations when off-screen
  • scroll-linked motion must not trigger continuous layout or paint on large surfaces

5. paint (medium-high)

  • paint-triggering animation is allowed only on small, isolated elements
  • do not animate paint-heavy properties on large containers
  • do not animate CSS variables for transform, opacity, or position
  • do not animate inherited CSS variables
  • scope animated CSS variables locally and avoid inheritance

6. layers (medium)

  • compositor motion requires layer promotion, never assume it
  • use will-change temporarily and surgically
  • avoid many or large promoted layers
  • validate layer behavior with tooling when performance matters

7. blur and filters (medium)

  • keep blur animation small (<=8px)
  • use blur only for short, one-time effects
  • never animate blur continuously
  • never animate blur on large surfaces
  • prefer opacity and translate before blur

8. view transitions (low)

  • use view transitions only for navigation-level changes
  • avoid view transitions for interaction-heavy UI
  • avoid view transitions when interruption or cancellation is required
  • treat size changes as potentially layout-triggering

9. tool boundaries (critical)

  • do not migrate or rewrite animation libraries unless explicitly requested
  • apply these rules within the existing animation system
  • never partially migrate APIs or mix styles within the same component

common fixes

css
/* layout thrashing: animate transform instead of width *//* before */ .panel { transition: width 0.3s; }/* after */  .panel { transition: transform 0.3s; }
/* scroll-linked: use scroll-timeline instead of JS *//* before */ window.addEventListener('scroll', () => el.style.opacity = scrollY / 500)/* after */  .reveal { animation: fade-in linear; animation-timeline: view(); }
js
// measurement: batch reads before writes (FLIP)// before — layout thrashel.style.left = el.getBoundingClientRect().left + 10 + 'px';// after — measure once, animate via transformconst first = el.getBoundingClientRect();el.classList.add('moved');const last = el.getBoundingClientRect();el.style.transform = `translateX(${first.left - last.left}px)`;requestAnimationFrame(() => { el.style.transition = 'transform 0.3s'; el.style.transform = ''; });

review guidance

  • enforce critical rules first (never patterns, tool boundaries)
  • choose the least expensive rendering work that matches the intent
  • for any non-default choice, state the constraint that justifies it (surface size, duration, or interaction requirement)
  • when reviewing, prefer actionable notes and concrete alternatives over theory

來源與署名

來源:ibelick/ui-skills位於skills/fixing-motion-performance提交587ea30

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架