|
| 1 | +var starting = 5; |
| 2 | + |
1 | 3 | function LoadingBar(color, parent) { |
2 | | - this.meter = $('<span>', {style: 'transition: width 1s ease; width:0%;'}); |
| 4 | + this.meter = $('<span>', {style: 'transition: width 0.5s ease; width:0%;'}); |
3 | 5 | this.elem = $('<div>', {style: 'display:none', class: 'meter animate ' + color}).append( |
4 | 6 | this.meter.append($('<span>')) |
5 | 7 | ); |
| 8 | + this.progress = starting; |
6 | 9 |
|
7 | 10 | parent = parent || $('body'); |
8 | 11 | parent.prepend(this.elem); |
9 | 12 |
|
10 | 13 | return this; |
11 | 14 | } |
12 | 15 |
|
13 | | -LoadingBar.prototype.start = function(percentage) { |
14 | | - percentage = percentage || 0; |
15 | | - this.meter.css('width', percentage + '%'); |
| 16 | +LoadingBar.prototype.start = function(progress) { |
| 17 | + if(progress) { |
| 18 | + this.progress = progress; |
| 19 | + } |
| 20 | + console.log('start', this.progress); |
| 21 | + this.meter.css('width', this.progress + '%'); |
16 | 22 | this.elem.show(); |
17 | 23 | }; |
18 | 24 |
|
19 | 25 | LoadingBar.prototype.end = function() { |
20 | | - this.elem.hide(); |
| 26 | + console.log('end', this.progress); |
| 27 | + this.update(100); |
| 28 | + this.progress = starting; |
21 | 29 | }; |
22 | 30 |
|
23 | | -LoadingBar.prototype.update = function(percentage) { |
24 | | - this.meter.css('width', percentage + '%'); |
| 31 | +LoadingBar.prototype.update = function(progress) { |
| 32 | + this.progress = progress; |
| 33 | + console.log('update', this.progress); |
| 34 | + this.meter.css('width', this.progress + '%'); |
| 35 | + if(this.progress === 100){ |
| 36 | + setTimeout(function(){ |
| 37 | + console.log('hide'); |
| 38 | + this.elem.hide(); |
| 39 | + }.bind(this), 500); |
| 40 | + } |
25 | 41 | }; |
26 | 42 |
|
27 | 43 | module.exports = LoadingBar; |
0 commit comments