Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- componentDidUpdate(previousProps) {
- previousProps.children.forEach( child => {
- let domNode = ReactDOM.findDOMNode( this.refs[child.key] );
- const newBox = domNode.getBoundingClientRect();
- const oldBox = this.state[key];
- const deltaX = oldBox.left - newBox.left;
- const deltaY = oldBox.top - newBox.top;
- requestAnimationFrame( () => {
- domNode.style.transform = `translate(${deltaX}px, ${deltaY}px)`;
- domNode.style.transition = 'transform 0s';
- requestAnimationFrame( () => {
- // In order to get the animation to play, we'll need to wait for
- // the 'invert' animation frame to finish, so that its inverted
- // position has propagated to the DOM.
- //
- // Then, we just remove the transform, reverting it to its natural
- // state, and apply a transition so it does so smoothly.
- domNode.style.transform = '';
- domNode.style.transition = 'transform 500ms';
- });
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement