NProgress updated with additional functionality
npm install nprogress-v2NProgress V2 and Next NProgress Bar become BProgress!
The nprogress-v2 and next-nprogress-bar packages remain available and usable in their current versions, but will no longer be maintained. We therefore advise you to migrate to @bprogress/core.
Go to the migration documentation
Add [index.js] and [index.css] to your project.
``html`
`bash`
npm install nprogress-v2
Also available via [unpkg] CDN:
- https://unpkg.com/nprogress-v2@1.0.0/dist/index.js
- https://unpkg.com/nprogress-v2@1.0.0/dist/index.css
Simply call start() and done() to control the progress bar.
`js`
NProgress.start();
NProgress.done();
Percentages: To set a progress percentage, call .set(n), where _n_ is a0..1
number between .
`js`
NProgress.set(0.0); // Sort a same as .start()
NProgress.set(0.4);
NProgress.set(1.0); // Sort a same as .done()
Incrementing: To increment the progress bar, just use .inc(). This
increments it with a random amount. This will never get to 100%: use it for
every image load (or similar).
`js`
NProgress.inc();
If you want to increment by a specific value, you can pass that as a parameter:
`js`
NProgress.inc(0.2); // This will get the current status value and adds 0.2 until status is 0.994
Force-done: By passing true to done(), it will show the progress bar
even if it's not being shown. (The default behavior is that _.done()_ will not
do anything if _.start()_ isn't called)
`js`
NProgress.done(true);
Get the status value: To get the status value, use .status
#### minimum
Changes the minimum percentage used upon starting. (default: 0.08)
`js`
NProgress.configure({ minimum: 0.1 });
#### maximum
Changes the maximum percentage used upon finishing. (default: 1)
`js`
NProgress.configure({ maximum: 0.9 });
#### template
You can change the markup using template. To keep the progressrole='bar'
bar working, keep an element with in there.
`js
NProgress.configure({
template:
,
});
`You can also set the template to
null to use your own template in your code.`js
NProgress.configure({
template: null,
});
`In your code, you can use the following template:
`html
`_Note: You can add multiple templates in your code to have multiple progress bars._
####
easing and speedAdjust animation settings using _easing_ (a CSS easing string) and _speed_ (in ms). (default:
ease and 200)`js
NProgress.configure({ easing: 'ease', speed: 500 });
`####
trickleTurn off the automatic incrementing behavior by setting this to
false. (default: true)`js
NProgress.configure({ trickle: false });
`####
trickleSpeedAdjust how often to trickle/increment, in ms.
`js
NProgress.configure({ trickleSpeed: 200 });
`####
showSpinnerTurn off loading spinner by setting it to false. (default:
true)`js
NProgress.configure({ showSpinner: false });
`####
barSelectorSpecify this to change the bar selector. (default:
[role="bar"])`js
NProgress.configure({ barSelector: '.my-custom-bar' });
`####
spinnerSelectorSpecify this to change the spinner selector. (default:
[role="spinner"])`js
NProgress.configure({ spinnerSelector: '.my-custom-spinner' });
`####
parentSpecify this to change the parent container. (default:
body)`js
NProgress.configure({ parent: '#container' });
`####
directionSpecify progress bar direction: ltr or rtl. (default
ltr)Customization
Just edit
index.css to your liking. Tip: you probably only want to find
and replace occurrences of #29d`.The included CSS file is pretty minimal... in fact, feel free to scrap it and make your own!
If you encounter any problems, do not hesitate to open an issue or make a PR here.
MIT