Skip to content

Instantly share code, notes, and snippets.

@pigeonfresh
Last active August 9, 2019 19:48
Show Gist options
  • Save pigeonfresh/6f9ce0a52a120ab7619fa335c273909b to your computer and use it in GitHub Desktop.
Save pigeonfresh/6f9ce0a52a120ab7619fa335c273909b to your computer and use it in GitHub Desktop.
A small class to be able to lerp a Greensock Timeline and handle it's progress
import { TimelineMax, TimelineLite, TweenMax } from 'gsap';
export default class LerpedTimeline {
public progress: number = 0;
public readonly timeline: TimelineMax | TimelineLite;
private readonly ease: number;
private currentProgress: number = 0;
constructor(timeline, ease: number = 0.1) {
this.timeline = timeline;
this.ease = ease;
TweenMax.ticker.addEventListener('tick', this.handleTick);
}
private handleTick = (): void => {
this.currentProgress = this.currentProgress + (this.progress - this.currentProgress) * this.ease;
this.timeline.progress(this.currentProgress);
};
public dispose() {
TweenMax.ticker.removeEventListener('tick', this.handleTick);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment