<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>纯CSS3音乐均衡器动画特效</title>
<style>
body {
margin: 0;
padding: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(135deg, #1a1a2e, #16213e);
overflow: hidden;
font-family: Arial, sans-serif;
}
.equalizer-container {
display: flex;
align-items: flex-end;
height: 300px;
padding: 20px;
background: rgba(0, 0, 0, 0.3);
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}
.bar-container {
display: flex;
flex-direction: column;
align-items: center;
margin: 0 10px;
}
.bar {
width: 30px;
background: linear-gradient(to top, #00b4db, #0083b0);
border-radius: 5px 5px 0 0;
margin-bottom: 5px;
box-shadow: 0 0 10px rgba(0, 180, 219, 0.5);
animation: equalize 1.5s ease infinite alternate;
}
.bar:nth-child(1) { height: 40px; animation-delay: -0.2s; }
.bar:nth-child(2) { height: 80px; animation-delay: -0.4s; }
.bar:nth-child(3) { height: 120px; animation-delay: -0.6s; }
.bar:nth-child(4) { height: 160px; animation-delay: -0.8s; }
.bar:nth-child(5) { height: 200px; animation-delay: -1.0s; }
.bar:nth-child(6) { height: 160px; animation-delay: -1.2s; }
.bar:nth-child(7) { height: 120px; animation-delay: -1.4s; }
.bar:nth-child(8) { height: 80px; animation-delay: -1.6s; }
.bar:nth-child(9) { height: 40px; animation-delay: -1.8s; }
.base {
width: 50px;
height: 10px;
background: #333;
border-radius: 0 0 5px 5px;
}
.controls {
position: absolute;
bottom: 30px;
display: flex;
gap: 20px;
}
.control-btn {
width: 50px;
height: 50px;
border-radius: 50%;
background: rgba(0, 180, 219, 0.7);
border: none;
color: white;
font-size: 20px;
cursor: pointer;
box-shadow: 0 0 10px rgba(0, 180, 219, 0.5);
transition: all 0.3s;
}
.control-btn:hover {
background: rgba(0, 180, 219, 1);
transform: scale(1.1);
}
.title {
position: absolute;
top: 30px;
color: white;
font-size: 24px;
text-shadow: 0 0 10px rgba(0, 180, 219, 0.8);
}
.link {
position: absolute;
bottom: 20px;
right: 20px;
color: #00b4db;
font-size: 14px;
text-decoration: none;
font-weight: bold;
}
@keyframes equalize {
0%, 100% {
height: 10px;
}
50% {
height: var(--random-height);
}
}
/* 添加一些背景音乐元素效果 */
.music-note {
position: absolute;
color: rgba(0, 180, 219, 0.7);
font-size: 24px;
animation: float-note 4s linear infinite;
opacity: 0;
}
@keyframes float-note {
0% {
transform: translateY(0) rotate(0deg);
opacity: 0;
}
10% {
opacity: 1;
}
90% {
opacity: 1;
}
100% {
transform: translateY(-200px) rotate(360deg);
opacity: 0;
}
}
</style>
</head>
<body>
<h1 class="title">CSS3音乐均衡器</h1>
<div class="equalizer-container">
<div class="bar-container">
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="base"></div>
</div>
<div class="bar-container">
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="base"></div>
</div>
<div class="bar-container">
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="base"></div>
</div>
</div>
<div class="controls">
<button class="control-btn">▶</button>
<button class="control-btn">⏸</button>
<button class="control-btn">⏹</button>
</div>
<script>
// 为每个均衡器条设置随机高度
document.querySelectorAll('.bar').forEach(bar => {
const randomHeight = Math.floor(Math.random() * 200) + 20;
bar.style.setProperty('--random-height', `${randomHeight}px`);
// 为每个条设置不同的动画延迟
const randomDelay = Math.random() * 2;
bar.style.animationDelay = `-${randomDelay}s`;
});
// 创建漂浮的音符
function createMusicNote() {
const note = document.createElement('div');
note.className = 'music-note';
note.textContent = '♪';
note.style.left = `${Math.random() * 100}%`;
note.style.bottom = '20%';
note.style.animationDuration = `${Math.random() * 3 + 2}s`;
document.body.appendChild(note);
setTimeout(() => {
note.remove();
}, 4000);
}
// 定期创建音符
setInterval(createMusicNote, 800);
</script>
</body>
</html>
纯CSS3音乐均衡器动画特效
于 2025-06-13 13:42:29 首次发布
996

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



