如何在没有clickevent的情况下使用react状态为元素集合设置动画?

时间:2018-09-18 15:16:57

标签: javascript css reactjs animation react-transition-group

我有一个类似的收藏列表:

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      items: [
        "https://images.unsplash.com/photo...",
        "https://images.unsplash.com/photo...",
        "https://images.unsplash.com/photo...",
        "https://images.unsplash.com/photo...",
        "https://images.unsplash.com/photo...",
        "https://images.unsplash.com/photo...",
      ]
    };
  }
}

这些收藏品是全屏图像,我希望对其进行动画处理。问题是我试图为它们设置动画,而没有任何点击事件(更像是循环),并且我希望它可以无限期地动画。

这是我到目前为止所拥有的:

  render() {

    const items = this.state.items.map((item, i) => {
      if (i === this.state.show) {
        return (
            <img src={item} alt="" className="bg" key={i}/>
        )
      } else {
        return null
      }
    });

    return (
      <div className="App">
        <div className="container">
          <div className="arrow" onClick={this.next}><ArrowLeft/></div>
          <div className="img-container">
            <ReactCSSTransitionGroup
                transitionName={this.state.slideDirection}
                transitionEnterTimeout={0}
                transitionLeaveTimeout={0}
            >
              {items}
            </ReactCSSTransitionGroup>
          </div>
          <div className="arrow" onClick={this.prev}><ArrowRight/></div>
        </div>
      </div>
    );
  }

0 个答案:

没有答案