css3动画

.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;
    }
}

forward代表保存最后一个样式

import { CSSTransition } from 'react-transition-group';
<CSSTransition
      in={showValidationMessage}
       timeout={300} 
       classNames="message"
       unmountOnExit
       onExited={() => {
         this.setState({
           showValidationButton: true,
         });
       }}
 >
.fade-enter{
    opacity: 0;
}
.fade-enter-active{
    opacity: 1;
    transition: opacity 1s ease-in;
}
.fade-enter-done{
    opacity: 1;
}

入场动画

.fade-exit{
    opacity: 1;
}
.fade-exit-active{
    opacity: 0;
    transition: opacity 1s ease-in;
}
.fade-exit-done{
    opacity: 0;
}

出场动画

<TransitionGroup>
    {
        this.state.list.map((item,index)=>{
        return(
            <CSSTransition
                in={this.state.show}
                timeout={500}
                classNames='fade'
                unmountOnExit
                onEntered={(el)=>{el.style.color='blue'}}
                appear={true}
                key={index}
            >
            <div>{item}</div>
            </CSSTransition>
        )
    })
    }
</TransitionGroup>

多个元素动画外层用TransitionGroup 包裹,每一个用CSSTransition 包裹

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值