Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. componentDidUpdate(previousProps) {
  2. previousProps.children.forEach( child => {
  3. let domNode = ReactDOM.findDOMNode( this.refs[child.key] );
  4.  
  5. const newBox = domNode.getBoundingClientRect();
  6. const oldBox = this.state[key];
  7.  
  8. const deltaX = oldBox.left - newBox.left;
  9. const deltaY = oldBox.top - newBox.top;
  10.  
  11. requestAnimationFrame( () => {
  12. domNode.style.transform = `translate(${deltaX}px, ${deltaY}px)`;
  13. domNode.style.transition = 'transform 0s';
  14.  
  15. requestAnimationFrame( () => {
  16. // In order to get the animation to play, we'll need to wait for
  17. // the 'invert' animation frame to finish, so that its inverted
  18. // position has propagated to the DOM.
  19. //
  20. // Then, we just remove the transform, reverting it to its natural
  21. // state, and apply a transition so it does so smoothly.
  22. domNode.style.transform = '';
  23. domNode.style.transition = 'transform 500ms';
  24. });
  25. });
  26. });
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement