查看: 84|回复: 0

react之路: react过渡动画(react-transition-group)

[复制链接]

1

主题

0

回帖

0

积分

热心网友

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2009-4-24
发表于 2019-7-8 16:29:00 | 显示全部楼层 |阅读模式

github仓库地址:https://github.com/wanghao12345/react-book

这里主要讲解使用react-transition-group里面的CSSTransition实现动画。

使用CSSTransition实现动画,一共分三步:

1.引用CSSTransition

  1 import { CSSTransition } from 'react-transition-group' 

2.使用CSSTransition将需要动画的元素包裹起来

1 <CSSTransition
2       in={this.state.focused}
3       timeout={200}
4       classNames='slide'
5 >
6     ........
7  </CSSTransition>
8 
9                        

in: 一个是否执行动画的标准,当in的值为true就开始执行入场动画,in的值为false就开始执行出场动画

timeout: 执行一个动画的时间

classNames:动画的class名称,为了描述具体动画做准备

3.样式描述动画效果

 1 .slide-enter {
 2     transition: all .2s ease-out;
 3 }
 4 .slide-enter-active {
 5     width: 240px;
 6 }
 7 .slide-exit {
 8     transition: all .2s ease-out;
 9 }
10 .slide-exit-active {
11     width: 160px;
12 }

.xxx-enter:入场动画过渡参数设置

.xxx-enter-active :入场动画的效果

.xxx-exit:出场动画的过渡参数设置

.xxx-exit-active:出场动画的效果

注意:xxx为第二步定义的CSSTransition的className

 



来源:https://www.cnblogs.com/wanghao123/p/11152005.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部