im trying to add a progressbar but sometimes it bugs out and fills too slow or too fast, most of the time it works fine though.
I also think that there must be a better way to programm this since mine does way to many calculations for a single progressbar i think.
Here is my Code:
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 gets called again as soon as its over since there will be the next slide of the slideshow directly after.
The progress value resembles the width of the progressbar, its always a percentage.
Where does the number 15.625 come from? Its simply a 64th of a second so the progressbar updates 64 times a second giving the illusion of moving smoothly.
My html is pretty basic:
<div class="progressbar" [ngStyle]="{'width': progress+'%'}"></div>
I hope you have a better approach than i did. Thanks in advance
[EDIT]: What i mean by it bugging out is that the progressbar sometimes starts filling late and therefor doesnt reach the end (100%) before the next slide appears and then the next ones timing is offset too. Sometimes it starts early and then reaches the end (100%) too quickly so it stays at 100% for a while until the next slide appears.