Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6de3a45

Browse files
committed
Merge pull request rstacruz#136 from ChrisCinelli/master
Smoother decelerating auto increments
2 parents 33878ab + bba86d6 commit 6de3a45

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

‎nprogress.js‎

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818

1919
var Settings = NProgress.settings = {
2020
minimum: 0.08,
21-
easing: 'ease',
21+
easing: 'linear',
2222
positionUsing: '',
23-
speed: 200,
23+
speed: 350,
2424
trickle: true,
25-
trickleRate: 0.02,
26-
trickleSpeed: 800,
25+
trickleSpeed: 250,
2726
showSpinner: true,
2827
barSelector: '[role="bar"]',
2928
spinnerSelector: '[role="spinner"]',
@@ -83,16 +82,16 @@
8382

8483
if (n === 1) {
8584
// Fade out
86-
css(progress, {
87-
transition: 'none',
88-
opacity: 1
85+
css(progress, {
86+
transition: 'none',
87+
opacity: 1
8988
});
9089
progress.offsetWidth; /* Repaint */
9190

9291
setTimeout(function() {
93-
css(progress, {
94-
transition: 'all ' + speed + 'ms linear',
95-
opacity: 0
92+
css(progress, {
93+
transition: 'all ' + speed + 'ms linear',
94+
opacity: 0
9695
});
9796
setTimeout(function() {
9897
NProgress.remove();
@@ -161,9 +160,26 @@
161160

162161
if (!n) {
163162
return NProgress.start();
163+
} else if(n > 1) {
164+
return;
164165
} else {
165166
if (typeof amount !== 'number') {
166-
amount = (1 - n) * clamp(Math.random() * n, 0.1, 0.95);
167+
if (n >= 0 && n < 0.25) {
168+
// Start out between 3 - 6% increments
169+
amount = (Math.random() * (5 - 3 + 1) + 3) / 100;
170+
} else if (n >= 0.25 && n < 0.65) {
171+
// increment between 0 - 3%
172+
amount = (Math.random() * 3) / 100;
173+
} else if (n >= 0.65 && n < 0.9) {
174+
// increment between 0 - 2%
175+
amount = (Math.random() * 2) / 100;
176+
} else if (n >= 0.9 && n < 0.99) {
177+
// finally, increment it .5 %
178+
amount = 0.005;
179+
} else {
180+
// after 99%, don't increment:
181+
amount = 0;
182+
}
167183
}
168184

169185
n = clamp(n + amount, 0, 0.994);
@@ -172,7 +188,7 @@
172188
};
173189

174190
NProgress.trickle = function() {
175-
return NProgress.inc(Math.random()*Settings.trickleRate);
191+
return NProgress.inc();
176192
};
177193

178194
/**
@@ -220,7 +236,7 @@
220236
if (NProgress.isRendered()) return document.getElementById('nprogress');
221237

222238
addClass(document.documentElement, 'nprogress-busy');
223-
239+
224240
var progress = document.createElement('div');
225241
progress.id = 'nprogress';
226242
progress.innerHTML = Settings.template;
@@ -229,7 +245,7 @@
229245
perc = fromStart ? '-100' : toBarPerc(NProgress.status || 0),
230246
parent = document.querySelector(Settings.parent),
231247
spinner;
232-
248+
233249
css(bar, {
234250
transition: 'all 0 linear',
235251
transform: 'translate3d(' + perc + '%,0,0)'
@@ -340,7 +356,7 @@
340356

341357
var queue = (function() {
342358
var pending = [];
343-
359+
344360
function next() {
345361
var fn = pending.shift();
346362
if (fn) {
@@ -355,10 +371,10 @@
355371
})();
356372

357373
/**
358-
* (Internal) Applies css properties to an element, similar to the jQuery
374+
* (Internal) Applies css properties to an element, similar to the jQuery
359375
* css method.
360376
*
361-
* While this helper does assist with vendor prefixed property names, it
377+
* While this helper does assist with vendor prefixed property names, it
362378
* does not perform any manipulation of values prior to setting styles.
363379
*/
364380

@@ -399,7 +415,7 @@
399415

400416
return function(element, properties) {
401417
var args = arguments,
402-
prop,
418+
prop,
403419
value;
404420

405421
if (args.length == 2) {
@@ -430,7 +446,7 @@
430446
var oldList = classList(element),
431447
newList = oldList + name;
432448

433-
if (hasClass(oldList, name)) return;
449+
if (hasClass(oldList, name)) return;
434450

435451
// Trim the opening space.
436452
element.className = newList.substring(1);
@@ -454,13 +470,13 @@
454470
}
455471

456472
/**
457-
* (Internal) Gets a space separated list of the class names on the element.
458-
* The list is wrapped with a single space on each end to facilitate finding
473+
* (Internal) Gets a space separated list of the class names on the element.
474+
* The list is wrapped with a single space on each end to facilitate finding
459475
* matches within the list.
460476
*/
461477

462478
function classList(element) {
463-
return (' ' + (element.className || '') + ' ').replace(/\s+/gi, ' ');
479+
return (' ' + (element&&element.className || '') + ' ').replace(/\s+/gi, ' ');
464480
}
465481

466482
/**
@@ -473,4 +489,3 @@
473489

474490
return NProgress;
475491
});
476-

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /