Pinned scroll story

ng-gsap/scroll-trigger

View source

injectScrollTrigger accepts the full ScrollTrigger.StaticVars surface — including pin — so the same primitive that drove the progress bar earlier can also pin a section and scrub through chapters. Everything below reads the progress signal directly; there's no separate gsap.timeline() to keep in sync with the DOM.

01

Scroll down

This panel pins in place while you scroll through it — the page keeps moving, the panel doesn't.

02

Signals drive it

progress() from injectScrollTrigger picks the active chapter and its crossfade — no separate timeline to keep in sync.

03

Keep scrolling

ScrollTrigger owns the pin and the scrub math; ng-gsap just mirrors its state as plain signals.

04

You're through

The section unpins here and the page continues normally underneath.

private story = viewChild.required<ElementRef>('story');

// pin, start, end — the full ScrollTrigger.StaticVars surface, not a bespoke
// pin API. injectScrollTrigger just mirrors whatever comes back as signals.
protected scroll = injectScrollTrigger({
  trigger: this.story,
  start: 'top top+=48',   // pin just below the viewport edge, not flush to it
  end: '+=200%',          // ~2 viewport heights of pinned scrolling
  pin: true,
});

// Progress is squeezed into the middle of the scroll so the first and last
// chapters hold at full opacity instead of peaking for a single frame.
private position = computed(() => {
  const eased = (this.scroll.progress() - HOLD) / (1 - HOLD * 2);
  return Math.min(1, Math.max(0, eased)) * (CHAPTERS.length - 1);
});

// each chapter's opacity is a plain function of that — the neighbouring pair
// crossfades and always sums to 1, so they never double-expose
protected opacityFor(index: number): number {
  return Math.max(0, 1 - Math.abs(this.position() - index));
}