- Overview
- Documents
NProgress.js is a nanoscopic progress bar. Featuring realistic trickle animations to convince your users that something is happening!
For slim progress bars like on YouTube, Medium
Source: ricostacruz.com
May 07, 2014 in Animation 5988 views
NProgress.js is a nanoscopic progress bar. Featuring realistic trickle animations to convince your users that something is happening!
For slim progress bars like on YouTube, Medium
Source: ricostacruz.com
1. INCLUDE CSS AND JS FILES
<link href='nprogress.css' rel='stylesheet' /> <script src='vendor/jquery-1.10.js'></script> <script src='nprogress.js'></script>
2. JAVASCRIPT
NProgress.start(); NProgress.done();
3. ADVANCED
Percentages: To set a progress percentage, call .set(n), where n is a number between 0..1.
NProgress.set(0.0); // Sorta same as .start() NProgress.set(0.4); NProgress.set(1.0); // Sorta 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).
NProgress.inc();
If you want to increment by a specific value, you can pass that as a parameter:
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)
NProgress.done(true);
Get the status value: To get the status value, use .status
4. CONFIGURATION
Change the minimum percentage using minimum.
NProgress.configure({ minimum: 0.1 });
You can change the markup using template. To keep the progress bar working, keep an element withrole='bar' in there.
NProgress.configure({ template: "<div class='....'>...</div>" });
Adjust animation settings using ease (a CSS easing string) and speed (in ms).
NProgress.configure({ ease: 'ease', speed: 500 });
Want to turn off trickling? Set trickle to false.
NProgress.configure({ trickle: false });
You can adjust the trickleRate (how much to increase per trickle) and trickleSpeed (how often to trickle, in ms).
NProgress.configure({ trickleRate: 0.02, trickleSpeed: 800 });
Want to turn off loading spinner? Set showSpinner to false.
NProgress.configure({ showSpinner: false });
Tagged with:
nprogress.js
progress
progress bar
happening
trickle animations
animations
loading
loading status
youtube
slim progress bars
Related Articles