律动频谱柱
Equalizer Bars
一排柱条错峰升降,高度像随节拍变化。
适用场景
提示音频预览正在播放,或呈现简单节拍。 让频谱柱跟随当前播放器。需要用柱高表示声音时,读入真实音量。
应用示例
播客收件箱中,点播某条语音片段后,该条目旁的几根柱条会随音量升降。暂停时柱条停住,听众在长列表里也能认出正在播的是哪一条。
AI 提示词
给【目标音频指示器】制作律动频谱柱。让每根柱条从底部按 scaleY 缩放,并设置不同的相位和幅度。需要准确反映播放时接入采样音量。暂停音频时停下,减少动态时显示固定柱条。
示例代码
保存为 HTML 文件后,用浏览器打开即可运行。代码与页面里的演示一致。
查看 HTML
<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>律动频谱柱</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.meter-bars { width: 133px; height: 78px; display: flex; justify-content: center; align-items: end; gap: 5px; padding-bottom: 5px; border-bottom: 1px solid #63d9b88c; }
.meter-bars i {
width: 9px; height: 61px; transform: scaleY(var(--rest, .54)); transform-origin: bottom;
background: linear-gradient(#dbf8ad, #64caad); border-radius: 3px;
animation: equalize .92s ease-in-out infinite alternate;
}
.meter-bars i:nth-child(2n) { --rest: .32; --high: .83; animation-delay: -.47s; }
.meter-bars i:nth-child(3n) { --rest: .77; --high: 1; animation-delay: -.73s; }
.meter-bars i:nth-child(4n) { --rest: .44; --high: .67; animation-duration: .68s; }
@keyframes equalize { 0% { transform: scaleY(var(--rest, .54)); } 100% { transform: scaleY(var(--high, .96)); } }
.motion-example { display: grid; justify-items: center; width: 100%; gap: 10px; }
.motion-specimen {
display: grid;
place-items: center;
width: min(100%, 295px);
height: 108px;
position: relative;
isolation: isolate;
}
.motion-example [data-motion] { animation-play-state: paused; }
.motion-example[data-playing] [data-motion] { animation-play-state: running; }
@media (prefers-reduced-motion: reduce) {
.motion-example [data-motion] { animation: none; }
.motion-example [data-loop-toggle] { display: none; }
}
</style>
</head>
<body>
<main class="demo">
<div class="motion-example">
<div class="motion-specimen" aria-hidden="true"><div class="meter-bars"><i data-motion></i><i data-motion></i><i data-motion></i><i data-motion></i><i data-motion></i><i data-motion></i><i data-motion></i></div></div>
<button class="demo-button" type="button" data-loop-toggle data-testid="effect-demo-loop-toggle">播放演示</button>
</div>
</main>
<script>
const example = document.querySelector('.motion-example');
const toggle = example.querySelector('[data-loop-toggle]');
toggle.addEventListener('click', () => {
const playing = example.toggleAttribute('data-playing');
toggle.textContent = playing ? "暂停演示" : "播放演示";
});
</script>
</body>
</html>UI Skills 原创示例