mirror of
https://github.com/badlogic/heissepreise.git
synced 2024-06-24 09:25:53 +02:00
32 lines
788 B
JavaScript
32 lines
788 B
JavaScript
class ProgressBar {
|
|
constructor(steps) {
|
|
this.progress = 0;
|
|
this.steps = steps ?? 0;
|
|
this.step = 100 / this.steps;
|
|
this.container = document.querySelector('[x-id="loader"]');
|
|
this.progressBar = this.container.querySelector(".progress-bar");
|
|
}
|
|
|
|
setSteps(steps) {
|
|
this.steps = steps;
|
|
this.step = 100 / steps;
|
|
}
|
|
|
|
addStep() {
|
|
this.progress += this.step;
|
|
this.progressBar.style.transform = `scaleX(${this.progress / 100})`;
|
|
if (this.progress >= 99) {
|
|
this.finished();
|
|
}
|
|
}
|
|
|
|
finished() {
|
|
const element = this.container;
|
|
setTimeout(function () {
|
|
element.classList.add("hidden");
|
|
}, 250);
|
|
}
|
|
}
|
|
|
|
exports.ProgressBar = ProgressBar;
|