react react-transition-group实现动画
import React,{ Component,Fragment } from 'react';
import './style.css';
import { CSSTransition,TransitionGroup } from 'react-transition-group';
class App extends Component{
constructor(props){
super(props);
his.state = {
show: true,
list:[1,2]
}
// this.handleToggle = this.handleToggle.bind(this)
this.handleAddItem = this.handleAddItem.bind(this)
}
render() {
return (
<Fragment>
{/*<CSSTransition
in={this.state.show}
timeout={1000}
classNames='fade'
unmountOnExit
onEntered={(el) => {
el.style.color="blue"
}}
appear={true}
>
<div>hello</div>
</CSSTransition>*/}
<TransitionGroup>
{
this.state.list.map((item,index)=>{
return (
<CSSTransition
key={ index }
timeout={1000}
classNames='fade'
unmountOnExit
onEntered={(el) => {
el.style.color="blue"
}}
>
<div >{ item }</div>
</CSSTransition>
)
})
}
</TransitionGroup>
{/*<div className={this.state.show?'show' : 'hide'}>hello</div>*/}
<button onClick={ this.handleAddItem }>toggle</button>
</Fragment>
)
}
// handleToggle() {
// this.setState({
// show: !this.state.show
// })
// }
handleAddItem(){
this.setState((prevState) => {
return {
list: [...prevState.list,'item']
}
})
}
}
export default App
style.css
.input{
border:1px dashed red;
}
/*.show{
opacity:1;
transition: all 1s ease-in;
}
.hide{
opacity:0;
transition: all 1s ease-in;
}*/
.show{
animation: show-item 2s ease-in forwards;
}
.hide{
animation: hide-item 2s ease-in forwards;
}
@keyframes show-item{
0%{
opacity:0;
color:red;
}
50%{
opacity:0.5;
color:green;
}
100%{
opacity:1;
color:blue;
}
}
@keyframes hide-item{
0%{
opacity:1;
color:red;
}
50%{
opacity:0.5;
color:green;
}
100%{
opacity:0;
color:blue;
}
}
.fade-enter{
opacity: 0;
}
.fade-enter-active .fade-appear{
opacity: 1;
transition: opacity 1s ease-in;
}
.fade-enter-done{
opacity: 1;
color:red;
}
.fade-exit{
opacity: 1;
}
.fade-exit-active{
opacity: 0;
transition: opacity 1s ease-in;
}
.fade-exit-done{
opacity: 0;
}
react react-transition-group实现动画的更多相关文章
- [RN] React Native 下拉放大动画
React Native 下拉放大动画 经测试,无法运行 https://www.jianshu.com/p/1c960ad75020
- React+React Router+React-Transition-Group实现页面左右滑动+滚动位置记忆
2018年12月17日更新: 修复在qq浏览器下执行pop跳转时页面错位问题 本文的代码已封装为npm包发布:react-slide-animation-router 在React Router中,想 ...
- [React] react+redux+router+webpack+antd环境搭建一版
好久之前搭建的一个react执行环境,受历史影响是webpack3.10.0和webpack-dev-server2.7.1的环境,新项目准备用webpack4重新弄弄了,旧的记录就合并发布了(在没有 ...
- React/React Native 的ES5 ES6写法对照表
//es6与es5的区别很多React/React Native的初学者都被ES6的问题迷惑:各路大神都建议我们直接学习ES6的语法(class Foo extends React.Component ...
- React/React Native 的ES5 ES6写法对照表-b
很多React/React Native的初学者都被ES6的问题迷惑:各路大神都建议我们直接学习ES6的语法(class Foo extends React.Component),然而网上搜到的很多教 ...
- [React] React Fundamentals: Integrating Components with D3 and AngularJS
Since React is only interested in the V (view) of MVC, it plays well with other toolkits and framewo ...
- 使用transform和transition制作CSS3动画
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- React: React组件的生命周期
一.简介 在前面的第二篇博文中对组件的生命周期虽然做了一个大略介绍,但总感觉说的过于简单,毕竟生命周期是React组件的核心部分.在我们熟练使用React挂载和合成组件来创建应用表现层的过程中,针对数 ...
- React: React的属性验证机制
一.简介 在开发中,属性变量类型的验证,几乎是任何语言都必须关注的问题,因为如果传入的数据类型不对,轻者程序运行仅仅是给出警告⚠️,严重的会直接导致程序中断,APP闪退或者web页面挂掉,这是很严重的 ...
- React/react相关小结
React React组件由React元素组成,React组件使用React.Component或React.PureComponent来生成:React元素使用JSX的语法来编写或使用React.c ...
随机推荐
- struts文件下载机制
Struts2 中使用 type="stream" 的 result 进行下载即可.只用提供一个输入流inputStream,剩下的输出工作struts帮我们做. 例子一: 1.可 ...
- P4001 [ICPC-Beijing 2006]狼抓兔子
题目地址:P4001 [ICPC-Beijing 2006]狼抓兔子 平面图 边与边只在顶点相交的图. 对偶图 对于一个平面图,都有其对应的对偶图. 平面图被划分出的每一个区域当作对偶图的一个点: 平 ...
- SPI总线协议及SPI时序图详解【转】
转自:https://www.cnblogs.com/adylee/p/5399742.html SPI,是英语Serial Peripheral Interface的缩写,顾名思义就是串行外围设备接 ...
- Git学习笔记06-版本回退
在实际中,向版本库提交多次后,几千行代码肯定不记得每次都改了什么,可以使用git log来查看提交日志.也就是git commit -m 后面填写的这部分内容 也可以使用git log --pre ...
- Linux中OCI开发库的配置
Oracle调用接口(Oracle Call Interface,简称OCI)提供了一组可对Oracle数据库进行存取的接口子例程(函数),通过在第三代程序设计语言(如C语言)中进行调用可达到存取Or ...
- linux学习之硬盘的存储原理和内部架构
原文地址:https://blog.csdn.net/tanggao1314/article/details/52074735 首先,让我们看一下硬盘的发展史: 1956年9月13日,IBM的IBM ...
- gnutls-3.5.18 static building for windows
gnutls-3.5.18 static building for windows Required libraries:1. libnettle 2. gmplib Optional librari ...
- Light OJ 1214
简单大数模拟题: #include<bits/stdc++.h> using namespace std; typedef long long ll; string Num; vector ...
- O(big oh) (big omega) (big theta)
big oh big omega big theta more
- 如何在同一台电脑上使用两个github账户(亲测有效)
1 前言 由于有两个github账号,要在同一台电脑上同步代码,需要给每一个账号添加一个SSH public key,此时推送时git push origin,不知道是哪个账号的远程仓库名称,所以需要 ...