React入门(五)React动画

2019-02-22  本文已影响0人  我拥抱着我的未来

React动画

(1)必须依赖react-transition-group
(2)类的使用以及钩子函数

(1) 引入

import { CSSTransition} from 'react-transition-group'

(2) 使用

 <CSSTransition
          in={this.state.flag}
          timeout={2000}
          appear={true}
          classNames="fade"
          unmountOnExit
          onEnter={el => {
            el.style.color = 'red'
          }}
        >
          <div>
            <div>hello</div>
          </div>
        </CSSTransition>

PS :类名

.fade-enter,
.fade-appear {
  transform: translate(0, 0);
}
.fade-appear-active {
  transform: translate(80%, 0);
  transition: all 2s linear;
}
.fade-enter-active {
  transform: translate(80%, 0);
  transition: all 2s linear;
}
.fade-enter-done {
  transform: translate(80%, 0);
}
.fade-exit {
  transform: translate(80%, 0);
}
.fade-exit-active {
  transform: translate(0, 0);
  transition: all 2s linear;
}
.fade-exit-done {
  transform: translate(0, 0);
  color: blue;
}

多个动画的特效。最外层必须用TransitionGroup包起来。

  <TransitionGroup key={index}>
                <CSSTransition
                  in
                  timeout={2000}
                  appear={true}
                  classNames="fade"
                  unmountOnExit
                  onEnter={el => {
                    el.style.color = 'red'
                  }}
                >
                  <List
                    content={item}
                    index={index}
                    deletedate={this.deleteone.bind(this)}
                  />
                </CSSTransition>
              </TransitionGroup>
上一篇下一篇

猜你喜欢

热点阅读