学习使用js实现进度条代码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Progress Bar</title>
<style>
#progress-bar-container {
width: 100%;
background-color: #eee;
border: 1px solid #ddd;
}
#progress-bar {
width: 0;
height: 30px;
background-color: #0252D9;
text-align: center;
line-height: 30px;
color: white;
transition: width 1s ease;
}
</style>
</head>
<body>
<div id="progress-bar-container">
<div id="progress-bar">0%</div>
</div>
<script>
function updateProgress(percentage) {
var progressBar = document.getElementById('progress-bar');
progressBar.style.width = percentage + '%';
progressBar.innerHTML = percentage + '%';
}
function simulateProgress() {
var progress = 0;
var interval = setInterval(function() {
progress += 2;
updateProgress(progress);
if (progress >= 100) {
clearInterval(interval);
}
}, 1000);
}
simulateProgress();
</script>
</body>
</html>