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 从公开仓库中收录这些内容。

举报或申请下架