Animate React component when unmount/leave

纵然是瞬间 提交于 2019-12-24 10:09:36

问题


I want to use Velocity to fade out a component when the component leaves . I'm calling the callback but there is no animation. What is wrong with the code below?

export class Foo extends Component {

      componentWillEnter(cb) {
        cb();
      }

      componentWillLeave(cb) {
         const node = findDOMNode(el);
         Velocity(node, { opacity: 0 }, { duration:200 });
         cb();
      }
}

回答1:


Found it on a GSAP post. The callback needs to be passed to Velocity as the complete function.

    export class Foo extends Component {
      componentWillEnter(cb) {
        cb();
      }
      componentWillLeave(cb) {
         const node = findDOMNode(el);
         Velocity(node, { opacity: 0 }, { duration:200, complete: cb });
      }

    ...
    }


来源:https://stackoverflow.com/questions/45822833/animate-react-component-when-unmount-leave

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!