时间: 2020-11-26|28次围观|0 条评论

用哪一个安装哪一个 npm i rc-queue-anim,然后引用,一定要写key!!!
http://motion.ant.design/components/queue-anim-cn#components-queue-anim-demo-simple

//定义react组件
import React,{Component} from 'react';
import ReactDom from 'react-dom'
import './components/assets/a.css'
import QueueAnim from 'rc-queue-anim'

class App2 extends React.Component{
    state={
        bl:false,
        l:100
    }
    render() {
        return (<div>
            <h3>动画</h3>
            <input type="button" value="按钮" onClick={()=>{
                this.setState({
                    bl:!this.state.bl,
                    l:Math.random()*300
                })
            }}>
            </input>
            {this.state.bl&&<div className="box" style={
   {left:this.state.l}}>
                box
            </div>}
        </div>)
    }
}
class App extends Component{
    state={
        bl:false,
        l:100
    }
    render (){  
        return(<div className="">
            <h3>动画 css transition</h3>
            <input type="button" value="按钮" onClick={()=>{
                this.setState({
                    bl:!this.state.bl
                })
            }}/>
            <QueueAnim type={['left','right']} leaveReverse>
                {this.state.bl&&<div className="box" style={
   {left:this.state.l}} key="1">
                    box
                </div>}
                {this.state.bl&&<div className="box2" style={
   {left:this.state.l}} key="2">
                    box
                </div>}
            </QueueAnim>
        </div>)
    }
}

// 渲染dom
ReactDom.render(
    <App />
    ,
    document.querySelector('#root')
);

在css内

.box{
    width: 100px;
    height:100px;
    position: absolute;left:100px;top:100px;
    background: red;
    /* transition: 0.5s ease all; */
}

.box2{
width: 100px;
height:100px;
position: absolute;left:100px;top:250px;
background: blue;
/*transition: 0.5s ease all;*/
}

转载于:https://www.cnblogs.com/sansancn/p/11161924.html

原文链接:https://blog.csdn.net/weixin_30342827/article/details/95652723

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《react-动画
   

还没有人抢沙发呢~