Scroll Progress

Fixed page-scroll progress indicator with configurable update throttling

View documentation

Mounted once, in a layout

The bar on this page is the real component, fixed to the top edge of the viewport. Scroll and watch it fill — it measures the document, not any container.

The bar is rendered right here, and it is the real component: fixed to the top edge of the viewport, one pixel tall, above every surface except the overlays. Scroll this page and watch the very top of the window fill from left to right.

It measures the document, not this box — window.scrollY against scrollHeight - clientHeight — so the percentage answers “how far through the page am I” rather than how far through any particular section.

That is also why it belongs in a layout, once. A second fixed instance would sit exactly on top of the first, since the preset owns the position. The examples below neutralise that position on purpose so the variants can be seen side by side.

Custom styling

Height, colour, and radius are ordinary Blade attributes. data-controller is not: the component sets it and ignores one passed from outside, so the required binding cannot be replaced by accident.
Note: these bars are taken out of their fixed position so they can be compared side by side. The width still comes from the controller, so they fill as you scroll.

default

class="h-2 bg-blue-500"

class="h-3 rounded-full bg-linear-to-r from-emerald-500 to-teal-400"

Only the visual attributes pass through. data-controller is set by the component and a value passed from outside is ignored, so the binding that makes the bar work cannot be replaced by accident.

Throttle delay

The scroll listener is throttled at 15 milliseconds by default. Scroll quickly and compare: the first bar tracks every frame, the second is deliberately slowed to 400 milliseconds so the stepping becomes visible — including what a leading-edge throttle costs when the scrolling stops.

:throttle-delay="0" — sem estrangulamento

:throttle-delay="400" — deliberately exaggerated

Scroll quickly and the two bars separate: the first tracks every frame, the second updates at most once every 400 milliseconds and lags behind in visible steps. The real default is 15, which is imperceptible — the exaggerated value here only exists to make the mechanism visible.

Watch what happens when you stop: the throttled bar keeps whatever position it last managed to apply, and only catches up on the next scroll event. The throttle fires on the leading edge and has no trailing call, so the final position of a burst is dropped rather than applied late. At 15 milliseconds that gap is a single frame; the larger the delay, the more of the page the bar can be wrong about.

Room to scroll

A progress bar needs a document taller than the viewport before it has anything to report, which is exactly the trap when demonstrating one: on a short page every bar sits at 100% and the component looks broken.

This block exists to give the page that height. Scroll from here back to the top and the bars above run backwards in step with the window.

The same caveat applies to Sticky and Back to Top: all three are scroll-driven, so their demos have to earn a scroll before they can show anything.

Turbo Drive keeps the controller connected across navigations, so the bar is re-measured on every render rather than re-initialised from scratch. Navigating away and back does not leave it stuck at the previous page's position.

When the whole document fits on screen there is no progress to report and the width stays where the first measurement put it — another reason the component belongs in a layout, next to content that actually scrolls.