Progress
A thin loading bar at the top of the page for visits that take a while.
Import it from pagefold/progress (about 1.2 KB minified and compressed, shared code included).
import PagefoldProgress from 'pagefold/progress'
new Pagefold({ plugins: [new PagefoldProgress({ color: '#00ff9c' })] })
The bar appears if a visit takes longer than delay, counted from the click until the new page is in place. That includes the animation out, so if yours lasts 400 ms, use a delay longer than that or the bar will show on every visit. It starts at initialValue, and moves forward slower and slower, so it never looks finished before it is. When the page is shown it runs to the end and fades out. If the visit fails, it disappears.
Two visits with the default settings:
It is a div with aria-hidden="true": it is decoration, not information.
Your own styles
new PagefoldProgress({ styles: false })
.pagefold-progress-bar {
position: fixed;
inset: 0 0 auto 0;
height: 4px;
background: linear-gradient(90deg, #1b1bff, #00ff9c);
transform-origin: 0 50%;
transition: transform 0.3s;
z-index: 9999;
}
Pagefold sets the transform: scaleX(...) itself, from 0 to 1.
Common problems
- The bar never appears. The visit finished before
delay(300 ms). That is the point. Lowerdelayto see it on quick visits while you test. - The bar flashes on every visit. The animation out lasts longer than
delay, and the time counts. Raisedelayabove it. - It looks different from my site. Set
styles: falseand style.pagefold-progress-baryourself. - It is hidden behind something. The default bar uses
z-index: 99999. Withstyles: false, set your own in the CSS.
Options
| Option | Type | Default | What it does |
|---|---|---|---|
className | string | 'pagefold-progress-bar' | Class of the bar element. |
transition | number | 300 | Duration of the movement and the fade out, in milliseconds. |
delay | number | 300 | Wait this long before showing the bar, so quick visits show nothing. |
initialValue | number | 0.25 | Where the bar starts, from 0 to 1. |
minValue | number | 0.1 | The bar never shows less than this, from 0 to 1. |
finishAnimation | boolean | true | Run to the end before hiding. If false it disappears. |
styles | boolean | true | Apply basic inline styles. Turn off to style the class yourself. |
color | string | '#1b1bff' | Color of the bar. |
height | number | 3 | Height in pixels. |