Performance Optimization

dylantarre/animation-principles/skills/12-by-problem-type/performance-optimization

作者 dylantarre83597134ba8f無授權條款99 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫9 個月前更新

Use when animation runs slow, janky, or causes frame drops

AI 產生的概覽

運用迪士尼十二項動畫原則診斷並修復緩慢或卡頓的網頁動畫。

功能
引導代理將卡頓、掉幀或遲緩等動畫症狀對應到具體動畫原則進行診斷。它提出修復建議,例如使用關鍵影格插值、錯開動畫、只對 transform 和 opacity 做動畫、暫停畫面外的動畫,以及遵循減少動態效果的偏好設定。它也提供排查清單和對比快速與緩慢做法的 CSS 程式碼範例。
適用情境
當動畫執行緩慢、卡頓、掉幀或在行動裝置上耗電時使用。適用於動畫介面的前端效能調校,包括版面重排與同時執行的動畫過多等情況。
執行需求
不需要指令碼或工具,僅為說明性指示。套用這些建議需要網頁前端專案,並能使用瀏覽器開發者工具進行效能分析。

Performance Optimization

Diagnose and fix slow or janky animations using Disney's 12 principles.

Problem Indicators

  • Frame rate drops below 60fps
  • Stuttering or choppy motion
  • UI feels sluggish
  • Battery drain on mobile
  • Layout thrashing

Diagnosis by Principle

Straight Ahead vs Pose-to-Pose

Issue: Calculating every frame in real-time Fix: Use pose-to-pose (keyframe) animation. Let the browser interpolate between states using CSS transitions or will-change.

Timing

Issue: Too many simultaneous animations Fix: Stagger animations. Offset start times by 50-100ms to reduce concurrent calculations.

Secondary Action

Issue: Too many secondary effects Fix: Remove non-essential secondary animations on low-power devices. Use prefers-reduced-motion query.

Solid Drawing

Issue: Animating expensive properties (width, height, top, left) Fix: Only animate transform and opacity. These are GPU-accelerated and skip layout/paint.

Staging

Issue: Animating off-screen elements Fix: Only animate what's visible. Use Intersection Observer to pause off-screen animations.

Quick Fixes

  1. Replace JS animations with CSS - Browser-optimized
  2. Use transform instead of position properties - GPU layer
  3. Add will-change sparingly - Hints to browser
  4. Reduce simultaneous animations - Stagger or sequence
  5. Lower animation complexity on mobile - Detect device capability

Troubleshooting Checklist

  • Check DevTools Performance tab for long frames
  • Verify animations use transform/opacity only
  • Count simultaneous animations (keep under 3-4)
  • Test on lowest-spec target device
  • Check for layout thrashing (forced reflows)
  • Verify will-change isn't overused
  • Test with CPU throttling enabled
  • Check if animations pause when tab is hidden

Code Pattern

css
/* Fast */.element {  will-change: transform;  transition: transform 200ms ease-out;}.element:hover {  transform: translateY(-4px);}
/* Slow - avoid */.element:hover {  top: -4px; /* Triggers layout */}

來源與署名

來源:dylantarre/animation-principles位於skills/12-by-problem-type/performance-optimization提交8359713

授權條款: 無授權條款

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

檢舉或申請下架