Skip to content

Instantly share code, notes, and snippets.

@joshwcomeau
Last active February 12, 2016 13:22
Show Gist options
  • Save joshwcomeau/a69808b8af11564986be to your computer and use it in GitHub Desktop.
Save joshwcomeau/a69808b8af11564986be to your computer and use it in GitHub Desktop.
Animating the Unanimatable
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( () => {
// Before the DOM paints, Invert it to its old position
domNode.style.transform = `translate(${deltaX}px, ${deltaY}px)`;
// Ensure it inverts it immediately
domNode.style.transition = 'transform 0s';
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment