问题
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