<!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>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #f5f5f5;
color: #333;
padding: 20px;
}
.container {
max-width: 800px;
width: 100%;
margin: 0 auto;
text-align: center;
}
h1 {
margin-bottom: 40px;
color: #2c3e50;
}
.progress-section {
background: white;
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
padding: 30px;
margin-bottom: 30px;
}
h2 {
margin-bottom: 20px;
color: #3498db;
}
/* 线性进度条 */
.progress-linear {
width: 100%;
height: 10px;
background: #ecf0f1;
border-radius: 5px;
overflow: hidden;
margin-bottom: 30px;
}
.progress-linear-bar {
height: 100%;
width: 0;
background: linear-gradient(90deg, #3498db, #2ecc71);
border-radius: 5px;
transition: width 0.3s ease;
animation: linearProgress 3s infinite;
}
@keyframes linearProgress {
0% { width: 0; }
50% { width: 100%; }
100% { width: 0; }
}
/* 圆形进度条 */
.progress-circle {
position: relative;
width: 120px;
height: 120px;
margin: 0 auto 30px;
}
.progress-circle-bg {
fill: none;
stroke: #ecf0f1;
stroke-width: 8;
}
.progress-circle-fill {
fill: none;
stroke: #3498db;
stroke-width: 8;
stroke-linecap: round;
stroke-dasharray: 314;
stroke-dashoffset: 314;
transform-origin: center;
transform: rotate(-90deg);
animation: circleProgress 3s infinite;
}
.progress-circle-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 24px;
font-weight: bold;
color: #2c3e50;
}
@keyframes circleProgress {
0% { stroke-dashoffset: 314; }
50% { stroke-dashoffset: 0; }
100% { stroke-dashoffset: 314; }
}
/* 波浪进度条 */
.progress-wave {
width: 200px;
height: 200px;
margin: 0 auto 30px;
position: relative;
border-radius: 50%;
background: #ecf0f1;
overflow: hidden;
}
.progress-wave-inner {
position: absolute;
width: 200%;
height: 200%;
left: -50%;
top: 50%;
background: #3498db;
border-radius: 40%;
animation: waveProgress 5s infinite linear;
}
@keyframes waveProgress {
0% {
transform: rotate(0deg);
top: 30%;
}
50% {
transform: rotate(180deg);
top: 10%;
}
100% {
transform: rotate(360deg);
top: 30%;
}
}
/* 按钮样式 */
.btn {
display: inline-block;
padding: 12px 24px;
background: #3498db;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
margin: 10px;
transition: all 0.3s;
}
.btn:hover {
background: #2980b9;
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}
.controls {
margin: 30px 0;
}
.footer {
margin-top: 50px;
color: #7f8c8d;
font-size: 14px;
}
.footer a {
color: #3498db;
text-decoration: none;
}
.footer a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>加载进度条动画效果</h1>
<div class="progress-section">
<h2>线性进度条</h2>
<div class="progress-linear">
<div class="progress-linear-bar"></div>
</div>
</div>
<div class="progress-section">
<h2>圆形进度条</h2>
<div class="progress-circle">
<svg viewBox="0 0 120 120">
<circle class="progress-circle-bg" cx="60" cy="60" r="50"></circle>
<circle class="progress-circle-fill" cx="60" cy="60" r="50"></circle>
</svg>
<div class="progress-circle-text">0%</div>
</div>
</div>
<div class="progress-section">
<h2>波浪进度条</h2>
<div class="progress-wave">
<div class="progress-wave-inner"></div>
</div>
</div>
<div class="controls">
<button class="btn" id="start-btn">开始加载</button>
<button class="btn" id="reset-btn">重置</button>
</div>
<div class="footer">
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const startBtn = document.getElementById('start-btn');
const resetBtn = document.getElementById('reset-btn');
const linearBar = document.querySelector('.progress-linear-bar');
const circleFill = document.querySelector('.progress-circle-fill');
const circleText = document.querySelector('.progress-circle-text');
const waveInner = document.querySelector('.progress-wave-inner');
let progressInterval;
let progress = 0;
// 开始加载
function startLoading() {
resetLoading();
progress = 0;
updateProgress();
progressInterval = setInterval(function() {
progress += 1;
if (progress >= 100) {
clearInterval(progressInterval);
}
updateProgress();
}, 50);
}
// 更新进度
function updateProgress() {
// 线性进度条
linearBar.style.width = progress + '%';
// 圆形进度条
const circumference = 314; // 2 * π * r (r=50)
const offset = circumference - (progress / 100) * circumference;
circleFill.style.strokeDashoffset = offset;
circleText.textContent = progress + '%';
// 波浪进度条
const waveHeight = 100 - progress;
waveInner.style.top = waveHeight + '%';
}
// 重置加载
function resetLoading() {
clearInterval(progressInterval);
progress = 0;
linearBar.style.width = '0';
circleFill.style.strokeDashoffset = '314';
circleText.textContent = '0%';
waveInner.style.top = '100%';
}
// 事件监听
startBtn.addEventListener('click', startLoading);
resetBtn.addEventListener('click', resetLoading);
// 初始动画
setTimeout(startLoading, 1000);
});
</script>
</body>
</html>
1455

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



