I have a Progressbar in Bootstrap that fills every 1 sec 10% of the progressbar.
The problem is, that the site lags over the whole browser (chrome), but why?
That's my code that fills the Progressbar
var isPaused = false;
$(window).scroll(function(){
var ScrollTop = parseInt($(window).scrollTop());
if (ScrollTop > 10) {
isPaused = true;
} else {
isPaused = false;
}
});
var timeleft = 1;
var table_updated = 0;
var timeleft_zahl = 10;
var tick = function() {
if(!isPaused && $("#page-1").hasClass("active") && !$(".modal").hasClass("show")) {
document.getElementById("progressBar").style.width = timeleft*10+"%";
document.getElementById("refreshcountdown").innerHTML = timeleft_zahl-1;
timeleft += 1;
timeleft_zahl -= 1;
if(timeleft >= 11){
notificationcheck();
timeleft = 0;
timeleft_zahl = 11;
if(table_updated >= 10) {
location.reload();
table_updated = 0;
} else {
get_table_data(1);
table_updated += 1;
}
}
}
}
timer = setInterval(tick, 1000);
So it's just simple.
I have a few options, like isPaused
and some other things that stops the progressbar filling, cause when user scroll, than it must stop.
But why does it lag? the Interval runs every 1000 (so 1 sec) to fill every 1 sec 10% if isPaused false and the other if things are correct