I am using framer motion, but the animation on exist for front-card is not working

//---------------------------------------------------
const FrontCard = ({ phrase, open }) => {
return (
<motion.div
onClick={() => open()}
style={{
backfaceVisibility: "hidden",
transformStyle: "preserve-3d",
}}
initial={{ opacity: 0 }}
animate={{ opacity: 1, transition: { duration: 1 } }}
// here is not working...
exit={{
rotateY: -180,
transition: { duration: 1, ease: "easeInOut" },
opacity: 0,
}}
>
{phrase}
</motion.div>
);
};
//---------------------------------------------------
const BackCard = ({ definition, id, term, remove }) => {
const { play, isFetching } = useVoiceContext({ text: term });
return (
<motion.div
style={{
backfaceVisibility: "hidden",
transformStyle: "preserve-3d",
}}
initial={{
rotateY: -180,
}}
animate={{
rotateY: 0,
transition: { duration: 1, ease: "easeInOut" },
}}
>
rest...
</motion.div>
);
};
//---------------------------------------------------
const FlipCard = (props) => {
const [opened, handlers] = useDisclosure(false); // from Mantine
return (
<div
style={{
perspective: "1000px",
}}
>
<AnimatePresence>
{!opened ? (
<FrontCard {...props} />
) : (
<BackCard {...props} />
)}
</AnimatePresence>
</div>
);
};
//---------------------------------------------------
const FrontCard = ({ phrase, open }) => {
return (
<motion.div
onClick={() => open()}
style={{
backfaceVisibility: "hidden",
transformStyle: "preserve-3d",
}}
initial={{ opacity: 0 }}
animate={{ opacity: 1, transition: { duration: 1 } }}
// here is not working...
exit={{
rotateY: -180,
transition: { duration: 1, ease: "easeInOut" },
opacity: 0,
}}
>
{phrase}
</motion.div>
);
};
//---------------------------------------------------
const BackCard = ({ definition, id, term, remove }) => {
const { play, isFetching } = useVoiceContext({ text: term });
return (
<motion.div
style={{
backfaceVisibility: "hidden",
transformStyle: "preserve-3d",
}}
initial={{
rotateY: -180,
}}
animate={{
rotateY: 0,
transition: { duration: 1, ease: "easeInOut" },
}}
>
rest...
</motion.div>
);
};
//---------------------------------------------------
const FlipCard = (props) => {
const [opened, handlers] = useDisclosure(false); // from Mantine
return (
<div
style={{
perspective: "1000px",
}}
>
<AnimatePresence>
{!opened ? (
<FrontCard {...props} />
) : (
<BackCard {...props} />
)}
</AnimatePresence>
</div>
);
};
7 Replies
vince
vince9mo ago
i'd put this in #front-end (unless someone said to put it here, but this looks like a frontend post to me)
missymae
missymae9mo ago
motion elements need a unique key prop to animate presence.
Ali
AliOP9mo ago
amazing! I tried it, issue fixed! but now it triggers another issue
Ali
AliOP9mo ago
missymae
missymae9mo ago
try adding mode='wait' in the AnimatePresence component. It looks like both sides are rendered at the same time for a moment.
Ali
AliOP9mo ago
amazing again! there is a little pause (empty space) before the back-card starts flipping, any idea?
Ali
AliOP9mo ago
Want results from more Discord servers?
Add your server