I'm tasked with creating a progress bar (actually, a timer that looks like a progress bar) that will be triggered on a click event. I need multiple bars as a person may click on multiple elements that will trigger the progress bar. This is the script I have now:
function createPbar(IDofpBar, timeOut, timeIncrement ) {
...grab dom elements and do the math...
i=0;
var newWidth = 0;
var x = setInterval(function(){
theBar.style.width = newWidth+"px"
newWidth = newWidth + bIncrement;
if (i == counter) {
clearInterval(x);
}
i++
}, timeIncrement*1000);
}
This works fine until I have more than one on the page at a time. When I trigger the second one, it affects the first one. I'm guessing it's due to reassigning the variables each time I trigger a new progress bar.
Is there a way to isolate the variables per call?