You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 11:19:34