【发布时间】:2019-06-02 02:14:04
【问题描述】:
我在我的应用中使用react-transition-group 制作动画。
我有一个弹出窗口,我想在两个内容之间制作动画。我想让第一个内容淡出,第二个内容出现在它的位置。
到目前为止,我遇到了一个问题,即在为第二个内容设置动画时,第二个内容出现在第一个内容下方,而第一个内容仍然可见。 (见截图)
任何帮助将不胜感激。
我的代码
const [stage, setStage] = useState('register');
function changeStage(stageVal) {
setStage(stageVal);
}
...
<Popup togglePopupWindow={togglePopupWindow} setStage={setStage}>
<CSSTransitionGroup
transitionName="example"
transitionEnterTimeout={500}
transitionLeaveTimeout={300}
>
{stage === 'register' && (
<>
<Form>
<h2>Register</h2>
<Input type="text" placeholder="Login" />
<Input type="email" placeholder="Email" />
<Input type="password" placeholder="Password" />
<Button text="Register" />
</Form>
<p>
<span>Already registered?</span>
<Button className="popup__login" text="Login" onClick={() => changeStage('login')} />
</p>
</>
)
}
{stage === 'login' && (
<Form>
<h2>Login</h2>
<Input type="text" placeholder="Login" />
<Input type="password" placeholder="Password" />
<Button text="Register" />
</Form>
)
}
</CSSTransitionGroup>
</Popup>
样式
.example-enter {
opacity: 0;
}
.example-enter.example-enter-active {
opacity: 1;
transition: opacity 500ms ease-in-out;
}
.example-leave {
opacity: 1;
}
.example-leave.example-leave-active {
opacity: 0;
transition: opacity 300ms ease-in-out;
}
【问题讨论】:
标签: reactjs react-transition-group