我已经成功使用ReactCSSTransitionGroup(我想),新加载的组件以其全部荣耀淡入。
问题在于,被替换的组件突然消失了,这对我来说是个问题,因为最终我希望我的组件在视口内进出过渡...
我似乎没有看到任何告诉离开的组件如何优雅消失的方法。
我是否遗漏了什么,或者ReactCSSTransitionGroup只能动画化正在进入的组件?
更新
以下是代码:
import React from "react";
import ReactDOM from "react-dom";
import { Router, Route, IndexRoute, hashHistory, Link } from "react-router";
import ReactCSSTransitionGroup from "react-addons-css-transition-group";
class PageOne extends React.Component {
render() {
return (
<ReactCSSTransitionGroup transitionName="example" transitionAppear={true} transitionAppearTimeout={500} transitionEnterTimeout={500} transitionLeaveTimeout={500}>
<div>
HI FROM PAGE ONE<br />
<br />
<Link to="two">Take me to Page Two</Link>
</div>
</ReactCSSTransitionGroup>
);
}
}
class PageTwo extends React.Component {
render() {
return (
<ReactCSSTransitionGroup transitionName="example" transitionAppear={true} transitionAppearTimeout={500} transitionEnterTimeout={500} transitionLeaveTimeout={500}>
<div>
HELLO FROM PAGE TWO<br />
<br />
<Link to="/">Go back to Page One</Link>
</div>
</ReactCSSTransitionGroup>
);
}
}
const app = document.getElementById('app');
ReactDOM.render(
<Router history={hashHistory}>
<Route path="/" component={PageOne}></Route>
<Route path="two" component={PageTwo}></Route>
</Router>,
app);
并且CSS的代码:
.example-enter {
opacity: 0.01;
}
.example-enter.example-enter-active {
opacity: 1;
transition: opacity 500ms ease-in;
}
.example-leave {
opacity: 1;
}
.example-leave.example-leave-active {
opacity: 0.01;
transition: opacity 300ms ease-in;
}