Framer Motion中使用useAnimate()与useEffect()实现退出动画失效问题求助
Framer Motion中使用useAnimate()与useEffect()实现退出动画失效问题求助
我现在尝试用新的方式,结合useAnimate钩子和useEffect来实现退出动画,但不知道为什么退出动画完全没触发。
下面是我写在useEffect函数里的代码:
const [scope, animate] = useAnimate(); const [isPresent, safeToRemove] = usePresence(); useEffect(() => { if (isPresent) { const enterAnimation = async () => { await animate([ [ "#title", { opacity: [0, 1], y: [-20, 0] }, { duration: 0.5, delay: stagger(0.2) }, ], [ "#text", { opacity: [0, 1], y: [-20, 0] }, { duration: 0.5, delay: stagger(0.2) }, ], ]); }; enterAnimation(); } else { const exitAnimation = async () => { await animate( "#title", { opacity: [1, 0], y: [0, 20] }, { duration: 0.5 }, ); safeToRemove(); console.log("exited"); }; exitAnimation(); } }, [selectedTab]);
另外还有相关的页面标记、<AnimatePresence>的使用等细节,希望有人能帮忙排查一下问题,感谢大家的帮助!
备注:内容来源于stack exchange,提问作者Ilir
相关产品推荐
相关产品推荐

