* 计算进度值
()
| 191 | * 计算进度值 |
| 192 | */ |
| 193 | private calcProgress() { |
| 194 | // 立即完成逻辑,采用快速步进值计算进度 |
| 195 | if (this.isCompletedImmediately) { |
| 196 | this.progress += this.fastStepValue |
| 197 | this.fastStepValue += 0.5 |
| 198 | return |
| 199 | } |
| 200 | |
| 201 | // 悬停 99% 时,跳出计算,减少性能损耗 |
| 202 | if (this.progress >= WaveLoading.progressThreshold) return |
| 203 | |
| 204 | if (!this.startTime) { |
| 205 | this.startTime = Date.now() |
| 206 | } |
| 207 | |
| 208 | // x: percent complete percent complete: elapsedTime / duration |
| 209 | // t: elapsed time elapsed time: currentTime - startTime |
| 210 | // b: beginning value start value |
| 211 | // c: change in value finish value |
| 212 | // d: duration duration |
| 213 | const time = Date.now() - this.startTime |
| 214 | const percent = time / this.options.duration |
| 215 | |
| 216 | if (percent <= 1) { |
| 217 | this.progress = easing[this.options.easing]( |
| 218 | // x, t, b, c, d |
| 219 | percent, |
| 220 | time, |
| 221 | 0, |
| 222 | 100, |
| 223 | this.options.duration |
| 224 | ) |
| 225 | |
| 226 | // 1、防止 progress 超出 100 |
| 227 | // 2、通过 easing 函数返回的值可能悬停 99.7,加 0.9 让进度达到阈值 |
| 228 | if (this.progress + 0.9 >= WaveLoading.progressThreshold) { |
| 229 | this.progress = WaveLoading.progressThreshold |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * 根据进度计算波纹 offsetTop 值 |