Transition封装了react-transition-group的Transition, 用于应用过渡效果, 它使用内联样式实现过渡效果
点击按钮查看效果
设置unmountOnExit属性为ture即可.
in属性为true的情况组件挂载时in属性为true, 默认不会执行过渡, 如果想要执行过渡需要同时设置appear属性为ture
刷新页面查看不同:
<Transition
//...other props
transition={{
in: { width: "400px", height: "200px" },
out: { width: "200px", height: "100px" },
transitionProperty: "width,height",
}}
>
{(ref, styles) => <div ref={ref} style={styles}></div>}
</Transition>
TransitionGroup直接导出于react-transition-group, 用于管理多个Transition列表
TransitionGroup会自动管理其孩子Transition的in和appear属性.
| 属性名 | 类型 | 是否必须 | 默认值 | 说明 |
|---|---|---|---|---|
| appear | boolean | undefined | no | 是否in为true时挂载时执行过渡 | |
| duration | TransitionDuration | undefined | no | 250 | Transition duration in ms |
| in | boolean | undefined | no | 进入过渡 | |
| timingFunction | string | undefined | no | "ease" | 过渡缓动函数 |
| transition | TransitionType | undefined | no | "fade" | 过渡名称 |
| unmountOnExit | boolean | undefined | no | true | 退场过渡完成后是否卸载组件, 初始时不挂载组件 |