antd mobile(五)react-router界面切换动画
来源:互联网 发布:布罗代尔 知乎 编辑:程序博客网 时间:2024/05/20 23:07
用antd mobile时就在纳闷怎么没有提供界面切换动画,还为之苦恼了半天,后来才发现界面切换的动画是由react router提供了,赶紧的试试吧。
第一步: 是安装ReactCSSTransitionGroup。
React为动画提供了一个附加组件ReactTransitionGroup,这个附加组件是动画的底层API,并且还提供了一个附件组件ReactCSSTransitionGroup,
ReactCSSTransitionGroup能够简单的实现基于css的动画和转换
cnpm install –save react-addons-css-transition-group
第二步:是修改app.js文件的人口。
修改前的代码是:
render() { return ( <div id="reactContainer"> { this.props.children } </div> ); }
修改后。
import React,{Component} from 'react';import { connect,dispatch } from 'react-redux' // 引入connectimport ReactCSSTransitionGroup from "react-addons-css-transition-group";import style from "./Container.css";class App extends Component { constructor(props, context) { super(props, context); } componentWillMount() { document.body.style.margin = "0px"; // 这是防止页面被拖拽 document.body.addEventListener('touchmove', (ev) => { ev.preventDefault(); }); } render() { return ( <ReactCSSTransitionGroup transitionName="transitionWrapper" component="div" className={style.transitionWrapper} transitionEnterTimeout={300} transitionLeaveTimeout={300}> <div key={this.props.location.pathname} style={{position:"absolute", width: "100%"}}> { this.props.children } </div> </ReactCSSTransitionGroup> ); }}// 利用connect将组件与Redux绑定起来export default connect((AppMd) => ({AppMd}))(App)
第三步:则为界面切换定义css样式:
Container.css的内容如下:
:global(.transitionWrapper-enter) { position: absolute; top: 0; background: #fff; z-index: 10000; opacity: 1; transform: translateX(100%);}:global(.transitionWrapper-enter.transitionWrapper-enter-active) { opacity: 1; transform: translateX(0); transition: all 0.4s ease-out;}:global(.transitionWrapper-leave) { opacity: 1; transform: translateX(0);}:global(.transitionWrapper-leave.transitionWrapper-leave-active) { opacity: 1; transform: translateX(-100%); transition: all 0.4s ease-out;}.transitionWrapper { position: relative;}
这样实现了界面切换功能。
阅读全文
0 0
- antd mobile(五)react-router界面切换动画
- antd mobile(六)react-router 左进右出切换界面
- react项目的组件库antd-mobile
- create-react-app + antd-mobile配置
- react+react-router 4.0+redux+antd 购物车实战项目
- 学习react,redux,router,antd的一些感悟(见解)
- React-Router+antd+webpack+babel的一个详细demo
- antd-mobile
- Create-React-App创建antd-mobile开发环境
- antd mobile(四) highcharts集成---采用react-highcharts
- 在react-native中引入antd-mobile遇到的问题
- Create-React-App创建antd-mobile开发环境
- 使用Create-React-App脚手架创建antd-mobile开发环境
- react中安装antd-mobile时出现错误
- react实战--antd、react-router-dom v4 解决菜单和地址同步问题
- React(antd和react-bootstrap)的HelloWorld Demo
- React导航栏效果(antd+react router4.0)
- Activty界面切换动画
- 微信emoji、gif图片的实现及小米一键清除逻辑
- 英语语法基础_限定词(数量限定词)
- 缓存初探
- HDU 1166 树状数组&&线段树模板1
- python protoc
- antd mobile(五)react-router界面切换动画
- 树的重量(树+枚举)
- JavaScript DOM对象
- python3--字典
- iOS 怎样获得设备及应用相关信息
- UVa --- 11210 中国麻将【暴力深搜】
- apt-get下载、安装的软件在哪里
- HDU
- zoj 1081 Points Within (判断点是否在多边形内)