简体   繁体   English

动画存在退出不工作帧运动

[英]Animate Presence exit not working framer motion

Animate presence exit prop is not working动画存在退出道具不起作用

what i am doing wrong?我做错了什么?

 <AnimatePresence> <motion.div initial={{ opacity: 0, x: "-100%" }} animate={{ opacity: 1, x: 0 }} exit={{ opacity: 0, x: "100%" }}> <h1>Head</h1> </motion.div> </AnimatePresence>

Fixed!!固定的!!

Fixed it by adding these two props to Switch:通过将这两个道具添加到 Switch 来修复它:

import {useLocation} from "react-router-dom";从“react-router-dom”导入 {useLocation};

const location = useLocation();常量位置 = useLocation();

<Switch location={location} key={location.pathname}>
//Routes
</Switch>

The reason that this is not working is that you have to explicitly specify the key of the child that you are conditionally rendering.这不起作用的原因是您必须明确指定您有条件渲染的子项的键。

Doc reference: https://www.framer.com/api/motion/animate-presence/#unmount-animations文档参考: https://www.framer.com/api/motion/animate-presence/#unmount-animations

In your case that is the <motion.div>在你的情况下是<motion.div>

I have some examples of AnimatePresense here我在这里有一些 AnimatePresense 的例子

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

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