reactjs - 退出动画在下一个 js 成帧器 Action 中不起作用?

标签 reactjs next.js framer-motion

我将 next js 用于我的应用程序和 framer 运动用于我的动画。我可以设置一个介绍动画,但所有退出动画都不起作用..

我已将代码封装在动画存在下,但它什么也没做。

我在这里错过了什么?

下面是我的示例代码:

<AnimatePresence>
            <motion.form onSubmit={e => { e.preventDefault(); }} className={styles['auth-modal-form']} initial="hidden" exit="formExit" animate="visible" variants={
                {
                    hidden:{
                        opacity:0,
                        translateX:-25
                    },
                    visible:{
                        opacity:1,
                        translateX:0,
                        transition:{
                            duration:.2
                        }
                    },
                    formExit:{
                        translateX:25,
                        transition:{
                            duration:1
                        }
                    }
                }
            } >
                <div className={styles['auth-icon-tray']}>
                    <div className={styles['icon-container']} onClick={()=>{
                        setEmailId('');
                        dispatch(setModalClose())
                        document.body.style.overflow = 'unset';
                        }} >
                            
                        <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
                            <path d="M3.33637 14.9467C2.89149 15.3807 2.88064 16.1836 3.34722 16.6394C3.8138 17.0951 4.59506 17.0842 5.03993 16.6502L9.98784 11.6914L14.9466 16.6394C15.3915 17.0951 16.1728 17.0951 16.6393 16.6285C17.0951 16.1728 17.0951 15.3915 16.6502 14.9467L11.6914 9.98789L16.6502 5.03998C17.0951 4.58425 17.1059 3.803 16.6393 3.34727C16.1728 2.89154 15.3915 2.88069 14.9466 3.33643L9.98784 8.28434L5.03993 3.33643C4.59506 2.89154 3.80295 2.88069 3.34722 3.34727C2.88064 3.803 2.89149 4.59509 3.33637 5.02914L8.29515 9.98789L3.33637 14.9467Z" fill="black"/>
                        </svg>
                        
                    </div>
                </div>
                <label className={styles['auth-modal-title']} >Sign in</label>
                <label className={styles['auth-modal-subtitle']} >Get access to all features</label>
                <input 
                    type="text"
                    name="email"
                    autoFocus
                    autoComplete="username email"
                    placeholder="Enter your email"
                    className={errorCondition ? styles['auth-modal-input-error'] :styles['auth-modal-input']}
                    onChange={(e)=>{setErrorCondition(false) ;setEmailHandler(e.target.value)}}
                    defaultValue={emailId}
                    onKeyDown={(e)=>{handleKeypress(e)}}
                />
                <label className={styles['auth-modal-error-message']} >{errorMessage}</label>
                <div className={styles['auth-modal-button-holder']}>
                    {( emailHandler == '')?(<button className={styles['auth-modal-button-faded']}>Continue</button>): emailAuthLoad ? <div className={styles['post-cell-loader']} /> : <button className={styles['auth-modal-button']} onClick={()=>{submitEmail()}}  >Continue</button>}
                    
                </div> 
            </motion.form>
        </AnimatePresence>

最佳答案

似乎您在用户提交表单时取消了整个模态组件,从而在此过程中杀死了 AnimatePresence。 试试这样的:

<AnimatePresence>
  { showModal && 
    <motion.form {...props}>
      //form content
    </motion.form>
</AnimatePresence>

动画存在应该包含安装/卸载组件的条件。

关于reactjs - 退出动画在下一个 js 成帧器 Action 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68522383/

相关文章:

reactjs - 覆盖 React Framer Motion 中的转换延迟

javascript - TouchableHighlight 在键盘打开时不接受按下事件

javascript - highcharts-react 甘特图 : get mouse coordinates from mouse-over

reactjs - React Hook useEffect 缺少依赖项 : 'setValid' . 如何删除此警告

cookies - NextJS 与 next-auth ,设置从 node.js 收到的 cookie

reactjs - 如何使用成帧器运动在圆上制作动画路径?

javascript - 当元素处于 View 中时(当您滚动到元素时)成帧器运动动画

javascript - ReactJs : How to prevent componentWillUpdate from re-rendering multiple times

javascript - 在 next.js/react 中映射时无法访问值

javascript - Now.sh 构建因 : Support for the experimental syntax 'decorators-legacy' isn't currently enabled 而中断