简体   繁体   English

Framer 运动出口 animation 也可以在映射的反应 div 元素上播放

[英]Framer motion exit animation also plays on mapped react div elements

I am new to Framer Motion, and I can't figure out this problem.我是 Framer Motion 的新手,我无法解决这个问题。 I am using React and I have an array of objects that I.map() through.我正在使用 React,并且我有一个 I.map() 通过的对象数组。 For each object, it will make a div.对于每个 object,它都会创建一个 div。

Here is my problem: I made this div a motion.div and I added an exit animation to it.这是我的问题:我将这个 div 设为 motion.div,并在其中添加了 exit animation。 But when I click on ONE element, all of the other elements also play the exit animation.但是当我单击一个元素时,所有其他元素也会播放出口 animation。 How can I prevent this from happening?我怎样才能防止这种情况发生? I only want the div that got clicked playing the exit animation, not the other divs.我只想要点击播放出口 animation 的 div,而不是其他 div。

BTW: the hover animations do work individually.顺便说一句:hover 动画可以单独工作。 eg whileHover={{scale: 1.03}}例如 whileHover={{scale: 1.03}}

Small example of code:代码的小例子:

{marvelMovies.map((movie, index) => 
   <motion.div exit={{opacity: 0}} transition={transition} className="movie" key={index}>
  
   
   </motion.div>
)}

Are you wrapping the divs in Animate Presence您是否将 div 包装在Animate Presence

<AnimatePresence>
{marvelMovies.map((movie, index) => 
   <motion.div exit={{opacity: 0}} transition={transition} className="movie" key={index} />)}
</AnimatePresence>

I made a code sandbox with a working example: https://codesandbox.io/s/framer-motion-multiple-item-animation-presence-sdmq2我用一个工作示例制作了一个代码沙箱: https://codesandbox.io/s/framer-motion-multiple-item-animation-presence-sdmq2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM