Beta Status
This library is still in early beta and the API is subject to change and may get daily breaking changes. If the docs and the package disagree, prefer the package and open an issue on GitHub or send a pull request with a fix.
Variants
variants gives you named animation states that can be reused across initial, animate, exit, and the while* props.
Props
variants:Record<string, variant>. The variant map.initial:variant label | string[] | false. Initial variant state.animate:variant label | string[]. Active variant state.exit:variant label | string[]. Exit variant state.whileHover,whileTap,whileFocus,whileInView,whileDrag:variant label | string[].custom:unknown. Payload passed to variant functions.inherit:boolean. Setfalseto stop parent variant inheritance.
Variant Shape
- A variant can be a target object.
- A variant can be a function:
(custom, current, velocity) => target object | variant label. - Arrays such as
animate={["visible", "selected"]}merge labels from left to right. - Parent transitions can orchestrate children with
when,delayChildren,staggerChildren, andstaggerDirection. stagger(interval, { from })returns a delay function fordelayChildren.
Example
const item = {
hidden: { opacity: 0, y: 12 },
visible: { opacity: 1, y: 0 },
};
<motion.div variants={item} initial="hidden" animate="visible" />;
Variants