Skip to content

Instantly share code, notes, and snippets.

@leonderijke
Created October 14, 2016 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonderijke/6f93c740b2859693f5fe09318fe0840a to your computer and use it in GitHub Desktop.
Save leonderijke/6f93c740b2859693f5fe09318fe0840a to your computer and use it in GitHub Desktop.
On a Blind Date with React: Animating the Avatars
componentDidMount() {
this._tl = new TimelineLite({ paused: true });
this._tl.add([
// Fade out the Avatar Info (name and background)
TweenLite.to(this._infoEl, 0.5, { opacity: 0, width: 0, margin: 0 }),
// Scale down the Avatar image
TweenLite.to(this._figureEl, 0.5, { scale: 0.75 })
]);
// Hide the Avatar Info completely
this._tl.set(this._infoEl, { display: 'none' });
if (this.props.small) {
// If this Avatar is small at the start, begin Timeline playback from the end of the timeline,
// essentially moving directly to its end state
this._tl.play(this._tl.endTime());
}
},
componentDidUpdate(prevProps) {
if (!prevProps.small && this.props.small) {
this._tl.play();
}
if (prevProps.small && !this.props.small) {
// Reverse playback to reverse the animation
this._tl.reverse();
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment