Smooth scrolling
ng-gsap
Lenis is a separate smooth-scroll library, not part of GSAP. It keeps the page's native scroll, so ScrollTrigger works with it unchanged once two things are wired up: Lenis runs on GSAP's ticker, and every Lenis scroll event calls ScrollTrigger.update. It is running on this page only, for as long as the page is open. Turn it off and scroll again to feel the difference.
Wheel
Lenis eases the wheel delta instead of jumping by it
Ticker
one requestAnimationFrame loop for Lenis and GSAP
Sync
every Lenis scroll event updates ScrollTrigger
import Lenis from 'lenis';
private scene = viewChild.required<ElementRef>('scene');
protected smooth = signal(true);
constructor() {
// Render effects never run on the server, so Lenis is never constructed there.
// Reading smooth() makes the toggle a dependency: off tears Lenis down, on
// builds a fresh one.
afterRenderEffect((onCleanup) => {
if (!this.smooth()) {
return;
}
const lenis = new Lenis(); // honours prefers-reduced-motion by default
const stopSync = lenis.on('scroll', ScrollTrigger.update);
const tick = (time: number) => lenis.raf(time * 1000); // ticker time is in seconds
gsap.ticker.add(tick);
gsap.ticker.lagSmoothing(0);
// runs when smooth() flips and again on destroy
onCleanup(() => {
gsap.ticker.remove(tick);
gsap.ticker.lagSmoothing(500, 33); // GSAP's defaults
stopSync();
lenis.destroy();
});
});
// ordinary scrubbed ScrollTriggers — they need no changes to work with Lenis
injectGSAP(() => {
for (const layer of gsap.utils.toArray<HTMLElement>('.layer')) {
gsap.to(layer, {
yPercent: -Number(layer.dataset['depth']) * 60,
ease: 'none',
scrollTrigger: { trigger: layer.parentElement, scrub: true },
});
}
}, { scope: this.scene });
}