Scroll Triggers
The 10 effects ST01–ST10: purpose, API, options, examples, reduced motion and cost.
Experimental and not on npm
Scroll triggers react to an element entering or leaving an area. They use IntersectionObserver and passive listeners: nothing intercepts the wheel, touch or keys. Content is only held hidden below the fold after hydration and never under reduced motion, so it is visible without JavaScript. Pass a preset name of inViewPresets or { rootMargin, threshold, root } as the trigger.
ST01 · Reveal on enter
<RevealOnScroll> plays any entrance preset when the element enters the area (trigger, default "default"). Content already visible when the page hydrates is not hidden.
- Import
@neshel-ui/animations/scroll- API
RevealOnScroll, revealOnEnter- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
"use client";
import { fadeUp } from "@neshel-ui/animations/entrance";
import { RevealOnScroll } from "@neshel-ui/animations/scroll";
export default function ST01Example() {
return (
<RevealOnScroll
preset={fadeUp}
trigger="half"
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
Plays when half of it is visible
</RevealOnScroll>
);
}Options: RevealOnEnterOptions
RevealOnEnterOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| initial | "hold" | "visible" | — | "hold" (default for imperative attachment): hide the start pose now, before paint. "visible":
keep the element as rendered until the first report (hydrated server markup). |
| mode | TriggerMode | — | ST03: "once" (default), "repeat" (re-arm on every leave) or "reverse" (play out on leave-back). |
| onEnter | () => void | — | ST04 callbacks. |
| onEnterBack | () => void | — | — |
| onLeave | () => void | — | — |
| onLeaveBack | () => void | — | — |
| options | Record<string, unknown> | — | Options merged over the preset's (appear, hold, replay, playback are managed). |
| preset(required) | AnyPreset | — | An Entrance definition or preset (fadeUp, clipCircle, …; for ST02 the stagger effect). |
| reducedMotion | ReducedMotion | — | — |
| trigger | InViewInput | "default" | Trigger area: an inViewPresets name or { rootMargin, threshold, root } (default "default"). |
ST02 · Stagger on enter
<StaggerOnScroll> plays the stagger effect on the children when their container enters. The per-child entrance, interval and order are options of the stagger.
- Import
@neshel-ui/animations/scroll- API
StaggerOnScroll, staggerOnEnter- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
Loading the example…
"use client";
import { fadeUp, type StaggerOptions, stagger } from "@neshel-ui/animations/entrance";
import { StaggerOnScroll } from "@neshel-ui/animations/scroll";
export default function ST02Example() {
return (
<StaggerOnScroll
preset={stagger}
options={{ preset: fadeUp, interval: 90 } satisfies StaggerOptions}
className="flex flex-wrap gap-3"
>
{["One", "Two", "Three", "Four"].map((item) => (
<div
key={item}
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
{item}
</div>
))}
</StaggerOnScroll>
);
}Options: RevealOnEnterOptions
RevealOnEnterOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| initial | "hold" | "visible" | — | "hold" (default for imperative attachment): hide the start pose now, before paint. "visible":
keep the element as rendered until the first report (hydrated server markup). |
| mode | TriggerMode | — | ST03: "once" (default), "repeat" (re-arm on every leave) or "reverse" (play out on leave-back). |
| onEnter | () => void | — | ST04 callbacks. |
| onEnterBack | () => void | — | — |
| onLeave | () => void | — | — |
| onLeaveBack | () => void | — | — |
| options | Record<string, unknown> | — | Options merged over the preset's (appear, hold, replay, playback are managed). |
| preset(required) | AnyPreset | — | An Entrance definition or preset (fadeUp, clipCircle, …; for ST02 the stagger effect). |
| reducedMotion | ReducedMotion | — | — |
| trigger | InViewInput | "default" | Trigger area: an inViewPresets name or { rootMargin, threshold, root } (default "default"). |
ST03 · Once, repeat, reverse
The mode of <RevealOnScroll> and of createScrollTrigger: "once" plays a single time, "repeat" arms it again on every leave, and "reverse" plays it backwards when scrolling back out.
- Import
@neshel-ui/animations/scroll- API
RevealOnScroll, createScrollTrigger- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
Loading the example…
"use client";
import { fadeUp } from "@neshel-ui/animations/entrance";
import { RevealOnScroll } from "@neshel-ui/animations/scroll";
const modes = ["once", "repeat", "reverse"] as const;
export default function ST03Example() {
return (
<div className="grid gap-3 sm:grid-cols-3">
{modes.map((mode) => (
<RevealOnScroll
key={mode}
preset={fadeUp}
mode={mode}
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
mode: {mode}
</RevealOnScroll>
))}
</div>
);
}Options: ScrollTriggerOptions
ScrollTriggerOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| mode | TriggerMode | "repeat" | "once" stops observing after the first enter (default "repeat"). |
| onChange | (state: TriggerState) => void | — | — |
| onEnter | () => void | — | before → active (scrolling forward into the area). |
| onEnterBack | () => void | — | after → active (scrolling back into the area). |
| onLeave | () => void | — | active → after (scrolled past). |
| onLeaveBack | () => void | — | active → before (scrolled back above the area's start). |
| trigger | InViewInput | — | — |
ST04 · Enter and leave callbacks
useInView returns a boolean, and useScrollTrigger the trigger state with onEnter, onLeave, onEnterBack and onLeaveBack. React re-renders only on those transitions; createScrollTrigger is the framework-free version.
- Import
@neshel-ui/animations/scroll- API
useInView, useScrollTrigger, createScrollTrigger- Stylesheet
- none needed
- Reduced motion
n/a— nothing moves by itself, so nothing changes- Performance
- Observers only: no work per frame. React state changes only on transitions.
"use client";
import { useInView } from "@neshel-ui/animations/scroll";
import { useRef } from "react";
export default function ST04Example() {
const ref = useRef<HTMLDivElement>(null);
const visible = useInView(ref, "half");
return (
<div
ref={ref}
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
{visible ? "At least half visible" : "Less than half visible"}
</div>
);
}Options: ScrollTriggerOptions
ScrollTriggerOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| mode | TriggerMode | "repeat" | "once" stops observing after the first enter (default "repeat"). |
| onChange | (state: TriggerState) => void | — | — |
| onEnter | () => void | — | before → active (scrolling forward into the area). |
| onEnterBack | () => void | — | after → active (scrolling back into the area). |
| onLeave | () => void | — | active → after (scrolled past). |
| onLeaveBack | () => void | — | active → before (scrolled back above the area's start). |
| trigger | InViewInput | — | — |
ST05 · In-view progress
inViewProgress writes --neshel-view-progress (0–1) on the element as it crosses the viewport, so your CSS can use it. range selects the part of the crossing; under reduced motion the value is 1.
- Import
@neshel-ui/animations/scroll- API
inViewProgress, ScrollEffect- Stylesheet
@neshel-ui/animations/scroll.css- Reduced motion
static— the decoration or content stays still- Performance
- Writes one custom property, natively with scroll timelines where supported and from cached geometry elsewhere.
"use client";
import "@neshel-ui/animations/scroll.css";
import { inViewProgress, ScrollEffect } from "@neshel-ui/animations/scroll";
export default function ST05Example() {
return (
<ScrollEffect
preset={inViewProgress}
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
Scroll the page: the bar is this card’s way through the viewport.
<span
aria-hidden="true"
className="mt-4 block h-2 origin-left bg-neshel-primary"
style={{ transform: "scaleX(var(--neshel-view-progress, 1))" }}
/>
</ScrollEffect>
);
}Options: InViewProgressOptions
InViewProgressOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| driver | DriverPreference | — | "auto" (default): native scroll timeline when verified, else JS. |
| range | readonly [RangeInput, RangeInput] | — | Range of the effect's own timeline (ignored with timeline). |
| reducedMotion | ReducedMotion | — | — |
| scrollAxis | ScrollAxis | "block" | Scroll axis of the effect's own timeline (default "block"). |
| smooth | boolean | SpringOptions | SpringPreset | — | SP10 spring smoothing of the effect's own timeline. |
| source | Element | Window | null | — | Scroll container of the effect's own timeline (default: the root scroller). |
| timeline | ScrollProgress | — | A shared timeline (e.g. from useScrollScene()); otherwise the effect creates one. |
ST06 · Direction-aware header
directionHeader hides a sticky header while scrolling forwards past offset and shows it when scrolling back, at the top, and whenever focus is inside it. data-neshel-header="hidden" exposes the state.
- Import
@neshel-ui/animations/scroll- API
directionHeader, ScrollEffect- Stylesheet
- none needed
- Reduced motion
instant— the end state appears at once- Performance
- Transform and opacity, one write per frame through the shared scheduler; no layout work per frame.
Loading the example…
"use client";
import {
type DirectionHeaderOptions,
directionHeader,
ScrollEffect,
} from "@neshel-ui/animations/scroll";
import { useState } from "react";
export default function ST06Example() {
const [source, setSource] = useState<HTMLElement | null>(null);
return (
<section
ref={setSource}
aria-label="Scrollable article"
tabIndex={0}
className="h-56 overflow-y-auto rounded-xl border border-neshel-border"
>
{source ? (
<ScrollEffect
preset={directionHeader}
options={{ source, offset: 40 } satisfies DirectionHeaderOptions}
className="sticky top-0 z-10 bg-neshel-primary p-3 text-neshel-primary-foreground"
>
Hides while you scroll down
</ScrollEffect>
) : null}
{Array.from({ length: 14 }, (_, index) => (
<p key={index} className="px-4 py-2">
Paragraph {index + 1}
</p>
))}
</section>
);
}Options: DirectionHeaderOptions
DirectionHeaderOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| duration | number | 220 | Slide duration in ms (default 220). |
| offset | number | — | Never hide above this scroll offset, px (0–2000, default 80). |
| onChange | (hidden: boolean) => void | — | — |
| reducedMotion | ReducedMotion | — | — |
| source | Element | Window | null | — | — |
| tolerance | number | — | Scroll distance in one direction before toggling, px (0–400, default 12). |
ST07 · Stuck state
stuckState sets data-neshel-stuck while a position: sticky element is stuck and calls onChange. Style the stuck state in your own CSS; nothing is animated.
- Import
@neshel-ui/animations/scroll- API
stuckState, ScrollEffect- Stylesheet
- none needed
- Reduced motion
n/a— nothing moves by itself, so nothing changes- Performance
- Observers only: no work per frame. React state changes only on transitions.
"use client";
import { ScrollEffect, type StuckStateOptions, stuckState } from "@neshel-ui/animations/scroll";
import { useState } from "react";
export default function ST07Example() {
const [stuck, setStuck] = useState(false);
return (
<div className="h-96">
<ScrollEffect
preset={stuckState}
options={{ onChange: setStuck } satisfies StuckStateOptions}
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground sticky top-20"
>
{stuck ? "Stuck to the top" : "In normal flow"}
</ScrollEffect>
</div>
);
}Options: StuckStateOptions
StuckStateOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| onChange | (stuck: boolean) => void | — | — |
| source | Element | Window | null | — | — |
ST08 · Section spy
useSectionSpy returns the id of the section above the activation line, and the last one at the end of the page. Use it for aria-current="location" in a table of contents.
- Import
@neshel-ui/animations/scroll- API
useSectionSpy, createSectionSpy- Stylesheet
- none needed
- Reduced motion
n/a— nothing moves by itself, so nothing changes- Performance
- Observers only: no work per frame. React state changes only on transitions.
Loading the example…
"use client";
import { useSectionSpy } from "@neshel-ui/animations/scroll";
import { useState } from "react";
const ids = ["spy-intro", "spy-usage", "spy-limits"];
export default function ST08Example() {
const [source, setSource] = useState<HTMLElement | null>(null);
const active = useSectionSpy(ids, { source });
return (
<div className="grid gap-3 sm:grid-cols-[8rem_1fr]">
<nav aria-label="Sections of the example" className="grid content-start gap-1">
{ids.map((id) => (
<a
key={id}
href={`#${id}`}
aria-current={active === id ? "location" : undefined}
className="aria-[current]:font-bold"
>
{id.slice(4)}
</a>
))}
</nav>
<section
ref={setSource}
aria-label="Scrollable sections"
tabIndex={0}
className="relative h-48 overflow-y-auto rounded-xl border border-neshel-border"
>
{ids.map((id) => (
<div key={id} id={id} className="h-40 p-4">
Section {id.slice(4)}
</div>
))}
</section>
</div>
);
}Options: SectionSpyOptions
SectionSpyOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| axis | ScrollAxis | — | — |
| line | number | — | Activation line as a fraction of the scrollport from its start (0–1, default 0.3). |
| onChange | (index: number, section: Element | undefined) => void | — | Called with the active index (-1 before the first section) and element. |
| source | Element | Window | null | — | — |
ST09 · Lazy activation
lazyEffect attaches another effect only while the element is near the viewport (trigger: "lazy", two viewports) and destroys it when it is far. Use it for long pages with many expensive effects.
- Import
@neshel-ui/animations/scroll- API
lazyEffect, ScrollEffect- Stylesheet
- none needed
- Reduced motion
n/a— nothing moves by itself, so nothing changes- Performance
- Observers only: no work per frame. React state changes only on transitions.
"use client";
import { tilt3D } from "@neshel-ui/animations/hover";
import { type LazyEffectOptions, lazyEffect, ScrollEffect } from "@neshel-ui/animations/scroll";
export default function ST09Example() {
return (
<ScrollEffect
preset={lazyEffect}
options={{ preset: tilt3D, trigger: "lazy" } satisfies LazyEffectOptions}
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground w-64"
>
The tilt is attached only near the viewport and destroyed far from it.
</ScrollEffect>
);
}Options: LazyEffectOptions
LazyEffectOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| keepAlive | boolean | — | Keep the effect attached after it first activates (default false: destroy when far). |
| onActiveChange | (active: boolean) => void | — | — |
| options | Record<string, unknown> | — | — |
| preset(required) | AnyPreset | — | Any effect definition or preset (Tilt3D-like heavy effects, …). |
| trigger | InViewInput | "lazy" | Activation area (default "lazy": two viewports around the viewport). |
ST10 · Trigger presets
inViewPresets names common trigger areas: default, eager, lazy, center, half, full and top. resolveInView turns a name or your own options into complete observer options.
- Import
@neshel-ui/animations/scroll- API
inViewPresets, resolveInView- Stylesheet
- none needed
- Reduced motion
n/a— nothing moves by itself, so nothing changes- Performance
- Observers only: no work per frame. React state changes only on transitions.
"use client";
import { inViewPresets, useInView } from "@neshel-ui/animations/scroll";
import { useRef } from "react";
export default function ST10Example() {
const ref = useRef<HTMLDivElement>(null);
const visible = useInView(ref, inViewPresets.full);
return (
<div
ref={ref}
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
{visible ? "Fully visible" : "Partly visible"} — {Object.keys(inViewPresets).join(", ")}
</div>
);
}Options: InViewOptions
InViewOptions
| Prop | Type | Default | Description |
|---|---|---|---|
| root | Element | null | — | Intersection root; omitted or null → the viewport. |
| rootMargin | string | — | CSS margin around the root (px or %), as in IntersectionObserver. |
| threshold | number | readonly number[] | — | — |