Overview
Well-optimized animations enhance user experience without compromising performance. This guide focuses on techniques that work efficiently with Despia’s GPU-accelerated rendering engine. Animation Performance Targets:- 60fps in normal operation
- Smooth degradation under Low Power Mode
- < 16.6ms per frame budget
- No janky or stuttering animations
CSS Transform and Opacity
GPU-Accelerated Properties
Usetransform and opacity for animations. These properties are GPU-accelerated and don’t trigger layout or paint.
Available Transform Functions
Transform Origin
Control the pivot point for transformations:CSS Transitions
Basic Transitions
Apply smooth transitions between states:Transition Timing
Choose appropriate durations:- User-triggered actions: 0.15s - 0.25s
- Standard UI transitions: 0.3s - 0.4s
- Large movements: 0.4s - 0.6s
- Never exceed 0.6s for UI animations
Transition Timing Functions
Recommended Easing Functions
CSS Animations
Keyframe Animations
Define reusable animation sequences:Complex Keyframes
Animation Properties
Animation Fill Mode
Hardware Acceleration
Forcing GPU Layers
Create composite layers for smoother animations:Will-Change Property
Hint to browser which properties will animate:will-change sparingly. Each will-change creates a composite layer consuming memory.
Managing Will-Change with JavaScript
JavaScript Animations
RequestAnimationFrame
UserequestAnimationFrame for JavaScript-driven animations:
Cancelable Animations
Performance Monitoring
Animation Libraries
Recommended Libraries
Lightweight options that work well with Despia:GSAP Example
Framer Motion Example
Motion One Example
Properties to Avoid
Layout-Triggering Properties
These properties trigger layout recalculation and should not be animated:Paint-Triggering Properties
These trigger paint but not layout (better than layout, but still expensive):Safe Alternatives
Staggered Animations
CSS Delays
JavaScript Stagger
GSAP Stagger
Scroll-Based Animations
Intersection Observer
Trigger animations when elements enter viewport:Scroll-Driven Animations
Accessibility
Reduced Motion
Respect user’s motion preferences:Conditional Animations
Accessible Alternatives
Loading Animations
Skeleton Screens
Spinners
Progress Indicators
Modal and Dialog Animations
Fade and Scale
Slide from Bottom
Page Transition Animations
Fade Transition
Slide Transition
Common Animation Patterns
Button Tap Feedback
Card Hover Effect
Toggle Switch
Ripple Effect
Performance Optimization
Debouncing Animations
Batching DOM Updates
Limiting Concurrent Animations
Testing Animations
Chrome DevTools
Manual FPS Testing
Common Mistakes
Animating Layout Properties
Too Many Will-Change
Blocking Main Thread
No Reduced Motion Support
Animation Performance Budget
Recommended Limits
| Metric | Target | Maximum |
|---|---|---|
| Animation Duration | 0.3s | 0.6s |
| Simultaneous Animations | 5 | 10 |
| Keyframe Complexity | 3-5 steps | 10 steps |
| Will-Change Elements | 2-3 | 5 |
| Animation FPS | 60fps | 50fps |
Performance Checklist
- Use transform and opacity only
- Apply will-change sparingly
- Remove will-change after animation
- Respect prefers-reduced-motion
- Limit concurrent animations
- Use requestAnimationFrame for JS animations
- Avoid animating layout properties
- Test on low-end devices
- Monitor frame rates during development
Platform Considerations
iOS Performance
- WKWebView handles GPU-accelerated animations efficiently
- Observe ~30fps under Low Power Mode constraints
- Transform and opacity maintain smoothness across power states
- Avoid complex box-shadow animations
Android Performance
- Performance varies by device
- Test on mid-range devices (4GB RAM)
- GPU acceleration generally good on modern Android
- Be conservative with simultaneous animations