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