Timeline
ng-gsap
A timeline is just something you build inside the injectGSAP callback. Because the callback reads stagger(), changing the slider reverts the old timeline and builds a new one — there is no teardown code in this component at all.
private stage = viewChild.required<ElementRef>('stage');
protected stagger = signal(0.12);
protected progress = signal(0);
private timeline: gsap.core.Timeline | undefined;
// Building the timeline inside the callback means the context owns it. Reading
// stagger() makes it a dependency: move the slider and the old timeline is
// reverted and a new one built. There is no teardown code in this component.
private anim = injectGSAP(() => {
this.timeline = gsap
.timeline({ onUpdate: () => this.progress.set(this.timeline?.progress() ?? 0) })
.from('.box', { opacity: 0, y: 40, stagger: this.stagger() })
.to('.box', { rotate: 90, stagger: this.stagger() }, '>-0.2');
}, { scope: this.stage });