【发布时间】:2019-10-11 09:18:44
【问题描述】:
我正在尝试在 React 中有条件地渲染一个组件并在它渲染时滑动它
包:
"react": "^16.8.6",
"react-transition-group": "^4.0.1",
代码sn-p:
{ 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 | |
| | | |
| | | |
| | | |
+------------------------------+
扩展应该在true时滑入,在false时滑出,它是来自代码sn-p的expandedDiv
div 只是在没有动画的情况下弹出。预期行为是从左到右的线性过渡
谢谢
【问题讨论】:
标签: css reactjs react-transition-group