Adding a progress bar has been a bit tricky for me - sometimes it fills too slowly or too quickly, but for the most part, it works fine.
I believe there must be a more efficient way to program this since my current method involves too many calculations for just one progress bar.
Below is the code I am using:
ts:
startProgressbar(timeToWait: number) {
this.progress = 0;
const interval = setInterval(() => {
let addvalue = (1 / timeToWait * 100) / 64;
this.progress += addvalue;
if (this.progress >= 100) {
this.progress = 100;
window.clearInterval(interval);
}
}, 15.625); }
The function is called again immediately after completion because the next slide of the slideshow follows.
The value of the progress reflects the width of the progress bar, always in percentage form.
Wondering about the number 15.625? It represents a 64th of a second, allowing the progress bar to update smoothly 64 times per second.
My HTML structure is quite simple:
<div class="progressbar" [ngStyle]="{'width': progress+'%'}"></div>
If you have a better solution than mine, I would greatly appreciate it. Thank you!
[EDIT]: Sometimes the progress bar starts filling late and does not reach 100% before the next slide appears, causing timing issues. Other times it fills up too quickly and remains at 100% until the next slide loads.