loading code fetching the highlighted snippet
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.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.container: () => containerEl) so useScroll can resolve the
bound element after mount — at script-run time the binding is still undefined.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.trackContentSize: true, so the readout
stays right without measuring the DOM yourself.scrollXProgress / scrollYProgress can run on a native scroll timeline.