<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文件下载进度条演示</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 0 auto;
padding: 20px;
text-align: center;
}
.progress-container {
width: 100%;
background-color: #f1f1f1;
border-radius: 5px;
margin: 20px 0;
}
.progress-bar {
height: 30px;
background-color: #4CAF50;
border-radius: 5px;
width: 0%;
transition: width 0.3s;
text-align: center;
line-height: 30px;
color: white;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #45a049;
}
.info {
margin-top: 20px;
font-size: 14px;
color: #666;
}
</style>
</head>
<body>
<h1>文件下载进度演示</h1>
<p>点击下方按钮模拟文件下载过程</p>
<button id="downloadBtn">开始下载</button>
<div class="progress-container">
<div id="progressBar" class="progress-bar">0%</div>
</div>
<div id="status"></div>
<div class="info">
</div>
<script>
document.getElementById('downloadBtn').addEventListener('click', function() {
const progressBar = document.getElementById('progressBar');
const statusDiv = document.getElementById('status');
// 重置进度条
progressBar.style.width = '0%';
progressBar.textContent = '0%';
statusDiv.textContent = '准备下载...';
// 模拟下载过程
let progress = 0;
const interval = setInterval(function() {
progress += Math.random() * 10;
if (progress >= 100) {
progress = 100;
clearInterval(interval);
statusDiv.textContent = '下载完成!';
// 下载完成后显示链接
statusDiv.innerHTML += '<br>感谢使用我们的服务';
}
progressBar.style.width = progress + '%';
progressBar.textContent = Math.floor(progress) + '%';
statusDiv.textContent = '下载中: ' + Math.floor(progress) + '%';
}, 300);
});
</script>
</body>
</html>
2121

被折叠的 条评论
为什么被折叠?



