簡體   English   中英

Framer Motion 退出和 AnimatePresence 在 Nextjs 中不起作用?

[英]Framer Motion exit and AnimatePresence not working in Nextjs?

我的exit道具或AnimatePresence不起作用。

我的變種:

const imgVariant = {
    initial: {
      opacity: 0,
      y: -100,
    },
    animate: {
      opacity: 1,
      y: 0,
      transition: {
        type: "spring",
        stiffness: 20,
      },
    },
    exit: {
      opacity: 0,
      y: 500,
      transition: {
        duration: 5,
      },
    },
  };

我的代碼:

<div className="h-screen bg-neutral-200 flex overflow-hidden">

        <AnimatePresence exitBeforeEnter>

          <div className="w-full grid place-items-center">
            <motion.img
              src={product.image}
              alt={product.name}
              className="h-[400px] object-cover z-10 cursor-pointer"
              variants={imgVariant}
              initial="initial"
              animate="animate"
              exit="exit"
              drag
              dragConstraints={{ top: 0, left: 0, right: 0, bottom: 0 }}
            />
          </div>
       </AnimatePresence>
</div>

initialanimate工作正常,但是當我改變路線時退出 animation 不會觸發,我在這里做錯了嗎?

您嘗試制作動畫的元素需要具有唯一的key道具。

<div className="h-screen bg-neutral-200 flex overflow-hidden">
    <AnimatePresence exitBeforeEnter>
        <div className="w-full grid place-items-center">

            <motion.img
              key={product.id}
              src={product.image}
              alt={product.name}
              className="h-[400px] object-cover z-10 cursor-pointer"
              variants={imgVariant}
              initial="initial"
              animate="animate"
              exit="exit"
              drag
              dragConstraints={{ top: 0, left: 0, right: 0, bottom: 0 }}
            />

        </div>
    </AnimatePresence>
</div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM