Animations Knowledge Base
Framer Motion Setup
npm install framer-motion
Basic Animations
import { motion } from 'framer-motion';
// Fade in
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 0.3 }}
>
Content
</motion.div>
// Slide up
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.5, ease: 'easeOut' }}
>
Content
</motion.div>
Scroll Animations
<motion.div
initial={{ opacity: 0, y: 50 }}
whileInView={{ opacity: 1, y: 0 }}
viewport={{ once: true, margin: '-100px' }}
transition={{ duration: 0.5 }}
>
Animates when in view
</motion.div>
Stagger Children
const container = {
hidden: { opacity: 0 },
show: {
opacity: 1,
transition: { staggerChildren: 0.1 }
}
};
const item = {
hidden: { opacity: 0, y: 20 },
show: { opacity: 1, y: 0 }
};
<motion.ul variants={container} initial="hidden" animate="show">
{items.map(i => (
<motion.li key={i} variants={item}>{i}</motion.li>
))}
</motion.ul>
Hover & Tap
<motion.button
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
transition={{ type: 'spring', stiffness: 400 }}
>
Click me
</motion.button>
Page Transitions
// AnimatePresence for exit animations
import { AnimatePresence } from 'framer-motion';
<AnimatePresence mode="wait">
<motion.div
key={pathname}
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -20 }}
transition={{ duration: 0.3 }}
>
{children}
</motion.div>
</AnimatePresence>
Reduced Motion
import { useReducedMotion } from 'framer-motion';
function Component() {
const shouldReduceMotion = useReducedMotion();
return (
<motion.div
animate={{ y: shouldReduceMotion ? 0 : 20 }}
transition={{ duration: shouldReduceMotion ? 0 : 0.3 }}
/>
);
}
CSS Animations
/* Fade in up */
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.animate-fade-in-up {
animation: fadeInUp 0.5s ease-out forwards;
}
/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
.animate-fade-in-up {
animation: none;
}
}
Animation Tokens
| Name |
Duration |
Easing |
| fast |
200ms |
ease-out |
| normal |
300ms |
ease-out |
| slow |
500ms |
ease-in-out |
Best Practices
- GPU properties only: transform, opacity
- Respect reduced motion: Always check preference
- Purpose: Every animation serves a purpose
- Subtle: Don't distract from content
- 60fps: Test on low-end devices