Last active
February 12, 2016 13:22
-
-
Save joshwcomeau/a69808b8af11564986be to your computer and use it in GitHub Desktop.
Animating the Unanimatable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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