Elevate UX with Framer Motion
@vilvaathibanpb
Micro-interactions are small, subtle, and often overlooked design elements that enhance user experience.
Trigger
Rules
Feedback
Loop and Mode
Trigger
Rules
Feedback
Loop and Mode
npm install framer-motion
When we create an animation with framer motion:
1. Create motion values (MV) internally
2. Track current value & velocity in MV
3. Use MV to calculate the next step of the animation
4. These happen outside the React render cycle
1. Initial
2. Target
3. Transition
return (
<h1 className="title">
Welcome to FrontMania
</h1>
)
return (
<motion.h1 className="title">
Welcome to FrontMania
</motion.h1>
)
return (
<motion.h1
initial={{ opacity: 0}}
animate={{ opacity: 1 }}
className="title"
>
Welcome to FrontMania
</motion.h1>
)
return (
<motion.h1
initial={{ opacity: 0}}
animate={{ opacity: 1 }}
transition={{ duration: 2}}
className="title"
>
Welcome to FrontMania
</motion.h1>
)
return (
<motion.h1
animate={{ scale: [0.8, 1, 1.2, 0.9, 1.1, 1] }}
transition={{ duration: 2}}
className="title"
>
Welcome to FrontMania
</motion.h1>
)
const h1Variant = {
initial: { opacity: 0 },
final: { opacity: 1 },
};
const spanVariant = {
initial: { opacity: 0 },
final: { opacity: 1, transition: { duration: 5 } },
};
return (
<motion.h1
initial="initial"
animate="final"
transition={{ duration: 2 }}
variants={h1Variant}
className="title"
>
Welcome to
<motion.span variants={spanVariant}>
FrontMania
</motion.span>
</motion.h1>
);
function Todo({ todo, index, removeTodo }) {
return (
<div
className="todo"
onClick={() => removeTodo(index)}
>
{todo.text}
</div>
);
}
// List
{todos.map((todo, index) => (
<Todo
key={index}
index={index}
todo={todo}
completeTodo={completeTodo}
removeTodo={removeTodo}
/>
))}
function Todo({ todo, index, removeTodo }) {
return (
<motion.div
key={index}
initial={{ x: -100, opacity: 0 }}
animate={{ x: 0, opacity: 1 }}
exit={{ x: 100, opacity: 0 }}
className="todo"
onClick={() => removeTodo(index)}
>
{todo.text}
</motion.div>
);
}
// List
<AnimatePresence>
{todos.map((todo, index) => (
<Todo
key={todo.text}
index={index}
todo={todo}
completeTodo={completeTodo}
removeTodo={removeTodo}
/>
))}
</AnimatePresence>
function Todo({ todo, index, removeTodo }) {
return (
<motion.div
key={index}
initial={{ x: -100, opacity: 0 }}
animate={{ x: 0, opacity: 1 }}
exit={{ x: 100, opacity: 0 }}
whileHover={{ scale: 1.2}}
className="todo"
onClick={() => removeTodo(index)}
>
{todo.text}
</motion.div>
);
}
// List
<AnimatePresence>
{todos.map((todo, index) => (
<Todo
key={todo.text}
index={index}
todo={todo}
completeTodo={completeTodo}
removeTodo={removeTodo}
/>
))}
</AnimatePresence>
<Reorder.Group axis="y" values={todos} onReorder={setTodos}>
{todos.map((todo, index) => (
<Reorder.Item key={todo} value={todo} className="todo">
{todo}
</Reorder.Item>
))}
</Reorder.Group>
<LayoutGroup>
<motion.div layout>
<motion.div layout>
<motion.div layout>
<LayoutGroup>
transform
opacity
clipPath
filter
background-color
motion
with `onUpdate`
.style
.repeatDelay
repeatType
- "mirror"
.damping
- 0
Thank you for being an wonderful audience