FIG-001/ SCROLL

scroll-linked progress.

useScroll emits a 0→1 motion value tracking a container's scroll position. Pass it through useSpring and drive transform: scaleX(progress) on a bar — it grows as the user scrolls.

  • useScroll({ container }) returns a scrollYProgress motion value that runs 0 at the top to 1 at the bottom. Reading $scrollYProgress directly gives you the raw scroll fraction.
  • Wrapping it in useSpring turns the linear progress into a smoothed motion value — the bar lags slightly and overshoots gently. Drop the spring if you want strict 1:1 scroll mapping.
  • The container is passed as a getter (container: () => containerEl) so useScroll can resolve the bound element after mount — at script-run time the binding is still undefined.
↩ all examples
pattern · useScroll + useSpring mode · live running source
// scroll-progress scroll 0%
01 ingest
02 normalize
03 index
04 rank
05 serve
useScroll → useSpring transform: scaleX
category · scroll
sheet · sheet 01 / 02
⟳ to re-run
FIG-002/ SCROLL

distance to the end.

useScroll also returns scrollYLength, the container's maximum scroll offset. Subtract scrollY from it to show how many pixels are left to scroll.

  • scrollYLength is the maximum scroll offset (scrollHeight − clientHeight for a container), so scrollYLength.current − scrollY.current is the distance left to scroll. scrollXLength does the same horizontally.
  • The lengths are recomputed when the container resizes and on the next scroll, or on any content size change with trackContentSize: true, so the readout stays right without measuring the DOM yourself.
  • The lengths always update in JavaScript. Only scrollXProgress / scrollYProgress can run on a native scroll timeline.
↩ all examples
pattern · scrollYLength − scrollY mode · live running source
// distance-to-end 0 px left
01 intro
02 setup
03 usage
04 options
05 returns
06 notes
07 faq
08 end
scrollYLength − scrollY max 0 px
category · scroll
sheet · sheet 02 / 02
⟳ to re-run

Scroll Progress