Agent skill
web-animation-patterns
Use when adding animations, transitions, or motion to web UIs. Covers library selection, CSS animations, Framer Motion, View Transitions API, FLIP technique, and reduced-motion accessibility.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/web-animation-patterns
SKILL.md
Web Animation Patterns
Library Selection
| Need | Use |
|---|---|
| Simple hover/toggle transitions | CSS transitions/animations |
| React layout + mount/unmount | Framer Motion |
| Complex sequenced timelines | GSAP |
| Page/route transitions | View Transitions API |
| Fine-grained imperative control | Web Animations API |
CSS Animations
Use transform and opacity only (compositor-only, 60fps). Add will-change before animation, remove after. Use cubic-bezier() for spring-like easing.
Framer Motion
Use variants for orchestrated animations with staggerChildren. AnimatePresence wraps conditional renders for exit animations. layout prop animates layout changes. LazyMotion + domAnimation for code splitting (~30KB savings).
View Transitions API
Call document.startViewTransition(() => updateDOM()) with feature detection fallback. Use view-transition-name CSS for element persistence across transitions.
FLIP Technique
First, Last, Invert, Play -- animate layout changes at 60fps.
function flipAnimate(el: HTMLElement, update: () => void) {
const first = el.getBoundingClientRect() // First
update() // DOM change
const last = el.getBoundingClientRect() // Last
const dx = first.left - last.left // Invert
const dy = first.top - last.top
el.animate([
{ transform: `translate(${dx}px, ${dy}px)` },
{ transform: 'translate(0, 0)' },
], { duration: 300, easing: 'ease-out' }) // Play
}
Reduced Motion
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
scroll-behavior: auto !important;
}
}
// Framer Motion respects this automatically, or override:
const prefersReduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches
Gotchas
- Layout thrashing: batch reads before writes; never interleave
getBoundingClientRect()with DOM mutations - Compositor-only: only
transformandopacityavoid layout/paint -- animatingwidth,height,top,leftis expensive will-change: add before animation, remove after; permanentwill-changewastes GPU memory- Framer Motion bundle: ~30KB min+gz; use
LazyMotion+domAnimationfeature for code splitting - AnimatePresence: requires direct children with stable
keyprops; fragments break exit animations - View Transitions: still limited cross-browser; always feature-detect with
document.startViewTransition
Cross-References
- frontend:responsive-web-design -- media queries and layout context for animation breakpoints
- frontend:accessibility-testing -- testing reduced-motion compliance and focus management
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?