废话不多说,直接上代码, 和上一篇相同的调用方式
const updateProgress = (newProgress) => {
if (!isShowing) {
overlay.style.display = "block";
isShowing = true;
}
const duration = 1000;
const steps = 100;
const stepIncrement = (newProgress - progress) / steps;
let stepCount = 0;
const performAnimation = setInterval(() => {
if (stepCount >= steps) {
clearInterval(performAnimation);
} else {
progress += stepIncrement;
percentageDisplay.textContent = progress.toFixed(2) + "%";
progressBar.style.width = `${progress}%`;
stepCount++;
}
}, duration / steps);
};