How can I animate a react.js component onclick and detect the end of the animation

后端 未结 6 1515
孤街浪徒
孤街浪徒 2020-12-28 13:19

I want to have a react component flip over when a user clicks on the DOM element. I see some documentation about their animation mixin but it looks to be set up for \"enter\

6条回答
  •  青春惊慌失措
    2020-12-28 13:37

    Upon clicks you can update the state, add a class and record the animationend event.

    class ClickMe extends React.Component {
      constructor(props) {
        super(props)
        this.state = { fade: false }
      }
      render() {
        const fade = this.state.fade
    
        return (
          
        )
      }
    }
    

    See the plnkr: https://next.plnkr.co/edit/gbt0W4SQhnZILlmQ?open=Hello.js&deferRun=1&preview

    Edit: Updated to reflect current React, which supports animationend events.

提交回复
热议问题