本文实例讲述了react使用CSS实现react动画功能。分享给大家供大家参考,具体如下:
react动画:
import React, { Component } from 'react'; class Boss extends Component { constructor(props) { super(props); this.state = { isShow:true } this.toTogger=this.toTogger.bind(this) } render() { return ( <div> <div className={this.state.isShow"htmlcode">.hide{opacity: 1;transition: all 1.5s ease-in;} .show{opacity: 0;transition: all 1.5s ease-in;}keyframes动画:
.hide{animation: hide-item 2s ease-in forwards;} .show{animation: show-item 2s ease-in forwards;} @keyframes hide-item{ 0%{ opacity: 0; color: red; } 50%{ opacity: 0.5; color: saddlebrown; } 100%{ opacity: 1; color: yellow; } } @keyframes show-item{ 0%{ opacity: 1; color:green; } 50%{ opacity: 0.5; color:greenyellow; } 100%{ opacity: 0; color: yellow; } }react-transition-group动画库:
import {CSSTransition} from 'react-transition-group'; render() { return ( <div> <CSSTransition in={this.state.isShow} timeout={2000} classNames="boss-text" unmountOnExit > {/* <div className={this.state.isShow"htmlcode">.boss-text-enter{opacity: 0;} .boss-text-enter-active{opacity: 1;transition: opacity 2000ms;} .boss-text-enter-done{opacity: 1;} .boss-text-exit{opacity: 1;} .boss-text-exit-active{opacity: 0;transition: opacity 2000ms;} .boss-text-exit-done{opacity: 0;}多DOM动画:
import React, { Component, Fragment } from 'react'; import List from './List.js'; import axios from 'axios'; import Boss from './Boss'; import {CSSTransition,TransitionGroup} from 'react-transition-group' class Test extends Component { constructor(props) { super(props); this.state={ inputValue:'aaa', list:[], } // this.add=this.add.bind(this); } addList() { this.setState({ list:[...this.state.list,this.state.inputValue], inputValue:'' }) } change(e) { this.setState({ // inputValue:e.target.value inputValue:this.input.value }) } delete(i) { // console.log(i); const list = this.state.list; list.splice(i,1); this.setState({ list:list }) } componentDidMount() { // console.log('componentDidMount'); axios.get('https://www.easy-mock.com/mock/5e1d3d1564a3c20d7f366f91/ReactDemo1/App') .then((res)=>{ console.log('获取数据'+JSON.stringify(res)); this.setState({ list:res.data.data }); }) .catch((error)=>{console.log('获取数据失败'+error)}); } render() { console.log('3-render'); return ( <Fragment> <div> <input ref={(input)=>{this.input=input}} value={this.state.inputValue} onChange={this.change.bind(this)}/> <button onClick={this.addList.bind(this)}>添加</button> </div> <ul> <TransitionGroup> { this.state.list.map((v,i)=>{ return( <CSSTransition timeout={2000} classNames='boss-text' unmountOnExit key={i} > <List key={i} content={v} index={i} delete={this.delete.bind(this)} /> </CSSTransition> ); }) } </TransitionGroup> </ul> <Boss/> </Fragment> ); } } export default Test;希望本文所述对大家react程序设计有所帮助。
标签:
react,CSS,动画
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“react使用CSS实现react动画功能示例”评论...
更新动态
2024年05月03日
2024年05月03日
- [7504]ReferenceSoundEdition-GreatGuitarTunes(2013)[GermanyHQCD]
- 刘嘉佳《往日时光HQ》头版限量[低速原抓WAV+CUE]
- 单依纯《纯情歌》开盘母带[低速原抓WAV+CUE]
- 杨乐婷《遥望HQ》头版限量编号[低速原抓WAV+CUE]
- 蔡琴《三十周年纪念版》6N纯银镀膜[正版CD低速原抓WAV+CUE][519M]
- 张学友《昨夜梦魂中》[FLAC][453M]
- 群星《17号音乐仓库2 第9期》[320K/MP3][150.23MB]
- 汤兰花.2000-一代佳人(环球唱片金曲系列风华再现)【WAV+CUE】
- 罗美玲.2005-生日领悟(EP)【华研国际】【WAV+CUE】
- 李佳薇《相反的是》WAV
- 试音碟《金指妙弹电子琴演奏》5CD[WAV]
- 【新世纪电子】Авирадж2023-ИллюзияОбмана(FLAC)
- 陈婧霏.2024-春色(EP)【有此山文化】【FLAC分轨】
- 郭富城.2000-无忌VS未来(EP)【华纳】【WAV+CUE】
- 群星.2003-追忆林振强3CD【华纳】【WAV+CUE】