gpt4 book ai didi

css - react-transition-group CSSTransition 滑入渲染

转载 作者:行者123 更新时间:2023-11-27 23:55:22 35 4
gpt4 key购买 nike

我试图让一个组件在 React 中有条件地呈现并在它呈现时滑动它

包:

"react": "^16.8.6",
"react-transition-group": "^4.0.1",

代码片段:

{ expanded && (
<CSSTransition in={expanded} timeout={500} classNames="slide">
<div className="expandedDiv"></div>
</CSSTransition>
)}

CSS:

.slide-enter {
transform: translateX(-100%);
transition: .3s linear;
}
.slide-enter-active {
transform: translateX(0%);
}
.slide-exit {
transform: translateX(0%);
transition: .3s linear;
}
.slide-exit-active {
transform: translateX(-100%);
}

结构:

+------------------------------+
| | | header |
| | |____________+
| | | content |
| | | |
| | | |
| nav | expanded | |
| | | |
| | | |
| | | |
+------------------------------+

Expanded应该在true时滑入,false时滑出,它是代码片段中的expandedDiv

div 只是弹出而没有动画。预期行为是从左到右的线性过渡

谢谢

最佳答案

我需要多看一点你的代码才能准确理解你想做什么。但如果我做对了,请尝试这样做:

<CSSTransition
in={expanded}
appear={true}
key = {this.props.location.key}
timeout={500}
classNames="slide">
<div className='expandedDiv'> </div>
</CSSTransition>

关于css - react-transition-group CSSTransition 滑入渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56298258/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com