| 169 | |
| 170 | |
| 171 | function Example6(onComplete){ |
| 172 | // EXAMPLE 1 --------------------------------------------- |
| 173 | console.log('\nExample 6 - Set dynamically the total progress'); |
| 174 | // create new progress bar using default values |
| 175 | const b1 = new _progress.Bar({}, _progress.Presets.shades_grey); |
| 176 | b1.start(200, 0); |
| 177 | |
| 178 | // the bar value - will be linear incremented |
| 179 | let value = 0; |
| 180 | |
| 181 | // 50ms update rate |
| 182 | const timer = setInterval(function(){ |
| 183 | // increment value |
| 184 | value++; |
| 185 | |
| 186 | // update the bar value |
| 187 | b1.update(value) |
| 188 | |
| 189 | // change the total value |
| 190 | if (value > 1500){ |
| 191 | b1.setTotal(3000); |
| 192 | }else if (value > 150){ |
| 193 | b1.setTotal(2000); |
| 194 | } |
| 195 | |
| 196 | // limit reached ? |
| 197 | if (value >= b1.getTotal()){ |
| 198 | // stop timer |
| 199 | clearInterval(timer); |
| 200 | |
| 201 | b1.stop(); |
| 202 | |
| 203 | // run complete callback |
| 204 | onComplete.apply(this); |
| 205 | } |
| 206 | }, 15); |
| 207 | } |