01Bar spectrum
One bar per frequency band, each growing with scaleY by how loud that band is. Bars have to grow off the floor, so transform-origin sits on the bottom edge.
Best forNow-playing indicator in a music player, podcast page header
scaleYtransform-origingetByteFrequencyData

<svg width="0" height="0" style="position:absolute" aria-hidden="true">
<defs>
<symbol id="ico-waveform" viewBox="0 0 256 256" fill="currentColor"><path d="M208 96v64H48V96Z" opacity=".2"/><path d="M56 96v64a8 8 0 0 1-16 0V96a8 8 0 0 1 16 0m32-72a8 8 0 0 0-8 8v192a8 8 0 0 0 16 0V32a8 8 0 0 0-8-8m40 32a8 8 0 0 0-8 8v128a8 8 0 0 0 16 0V64a8 8 0 0 0-8-8m40 32a8 8 0 0 0-8 8v64a8 8 0 0 0 16 0V96a8 8 0 0 0-8-8m40-16a8 8 0 0 0-8 8v96a8 8 0 0 0 16 0V72a8 8 0 0 0-8-8"/></symbol>
<symbol id="ico-play" viewBox="0 0 256 256" fill="currentColor"><path d="M228.23 134.69L84.15 222.81A8 8 0 0 1 72 216.12V39.88a8 8 0 0 1 12.15-6.69l144.08 88.12a7.82 7.82 0 0 1 0 13.38" opacity=".2"/><path d="M232.4 114.49L88.32 26.35a16 16 0 0 0-16.2-.3A15.86 15.86 0 0 0 64 39.87v176.26A15.94 15.94 0 0 0 80 232a16.07 16.07 0 0 0 8.36-2.35l144.04-88.14a15.88 15.88 0 0 0 0-27.02M80 215.94V40l143.83 88Z"/></symbol>
<symbol id="ico-pause" viewBox="0 0 256 256" fill="currentColor"><path d="M208 48v160a8 8 0 0 1-8 8h-40a8 8 0 0 1-8-8V48a8 8 0 0 1 8-8h40a8 8 0 0 1 8 8M96 40H56a8 8 0 0 0-8 8v160a8 8 0 0 0 8 8h40a8 8 0 0 0 8-8V48a8 8 0 0 0-8-8" opacity=".2"/><path d="M200 32h-40a16 16 0 0 0-16 16v160a16 16 0 0 0 16 16h40a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16m0 176h-40V48h40zM96 32H56a16 16 0 0 0-16 16v160a16 16 0 0 0 16 16h40a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16m0 176H56V48h40z"/></symbol>
</defs>
</svg>
<main class="stage">
<div class="bs is-demo" id="bs">
<p class="bs__hint"><svg class="bs__ico" aria-hidden="true"><use href="#ico-waveform"/></svg><span>Press play and it moves with real sound</span></p>
<div class="bs__bars" id="bars" aria-hidden="true"></div>
<div class="bs__foot">
<button class="bs__play" id="play" type="button" aria-pressed="false">
<svg class="bs__ico bs__ico--play" aria-hidden="true"><use href="#ico-play"/></svg>
<svg class="bs__ico bs__ico--pause" aria-hidden="true"><use href="#ico-pause"/></svg>
<span id="playLabel">Play</span>
</button>
<p class="bs__level">
<span class="bs__levelLabel">Loudest band</span>
<b class="bs__levelBox">
<span class="bs__levelText" id="levelText" aria-live="polite">Bass</span>
<span class="bs__loop" aria-hidden="true"><i>Bass</i><i>Mid</i><i>Treble</i></span>
</b>
</p>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 막대 스펙트럼 — AnalyserNode 의 주파수 구간 하나가 막대 하나가 된다.
// 막대는 바닥에 붙어 자라는 요소라 transform-origin 을 아래 변에 둔다 (blog-demo 규칙 8 의 "붙는 지점" 예외).
// 격자 미리보기(.is-demo)는 사전에 정해 둔 스펙트럼 시퀀스를 CSS 키프레임으로 재생한다 —
// AnalyserNode 는 실제 재생 중에만 값이 나와 렌더러의 애니메이션 시계로는 잡히지 않는다.
// 사람이 재생 버튼을 누르면 JS 가 .is-demo 를 떼고 진짜 Web Audio 값으로 --h 를 쓴다.
$duration: $dur-quick;
$easing: $ease-spring;
$color: $stage-yellow;
@include stage($stage-ink);
.bs { display: flex; flex-direction: column; align-items: center; gap: $sp-3; width: 100%; max-width: 400px; }
.bs__hint {
display: flex; align-items: center; gap: $sp-1; margin: 0;
font-weight: 700; font-size: clamp(11px, 3vw, 12px); color: $subject-cream;
}
.bs__ico { width: 16px; height: 16px; color: $color; }
.bs__bars {
display: grid; grid-template-columns: repeat(32, 1fr); gap: $sp-1;
align-items: end; width: 100%; height: 104px;
}
// --h 는 JS 가 실제 소리에서 써 넣는 높이(0~1). 값이 없을 때의 정적 모습은 낮은 막대 줄이다.
.bs__bar {
height: 100%; border-radius: $r-xs;
background: linear-gradient(180deg, $subject-mint 0%, $color 60%, #cdb599 100%);
transform-origin: bottom center;
transform: scaleY(var(--h, .08));
transition: transform $duration $ease-out;
}
.bs__foot { display: flex; align-items: center; justify-content: center; gap: $sp-4; width: 100%; }
.bs__play {
display: inline-flex; align-items: center; gap: $sp-1;
border: 0; border-radius: $r-pill; padding: $sp-2 $sp-4;
background: $color; color: $subject-ink; cursor: pointer;
font-family: inherit; font-weight: 800; font-size: clamp(11px, 3vw, 12px); line-height: 1;
}
.bs__ico--pause { display: none; }
.bs__play[aria-pressed="true"] .bs__ico--play { display: none; }
.bs__play[aria-pressed="true"] .bs__ico--pause { display: inline-block; }
.bs__play .bs__ico { color: $subject-ink; }
.bs__level { margin: 0; display: flex; align-items: center; gap: $sp-2; }
.bs__levelLabel { font-weight: 700; font-size: clamp(10px, 2.6vw, 11px); color: rgba($subject-cream, .82); }
.bs__levelBox {
position: relative; display: grid; place-items: center;
min-width: 40px; height: 20px; border-radius: $r-xs; padding: 0 $sp-1;
background: rgba($subject-cream, .16); color: $subject-cream;
font-weight: 800; font-size: clamp(11px, 3vw, 12px); line-height: 1;
}
.bs__loop { position: absolute; inset: 0; display: grid; place-items: center; visibility: hidden; }
.bs__loop i { grid-area: 1 / 1; font-style: normal; visibility: hidden; }
// ── 격자 미리보기 루프 ─────────────────────────────────────────────
// 한 키프레임을 32개 막대가 공유하고, 음수 지연으로 구간 번호만큼 위상을 민다.
// 음수 지연이라 2초 루프가 끝에서 닫힌다 (양수 지연은 캡처 창 끝에서 막대가 순간이동한다 — 285 실측).
// 봉우리는 2초에 세 번(1.5Hz)이라 WCAG 2.3.1 의 초당 3회 한계 아래다.
.bs.is-demo .bs__bar {
animation-name: bsWave; animation-duration: $dur-loop; animation-timing-function: $easing;
animation-iteration-count: infinite; animation-fill-mode: backwards;
animation-delay: calc(var(--i) * -56ms);
transition: none;
}
@keyframes bsWave {
0% { transform: scaleY(.10); }
14% { transform: scaleY(.92); }
28% { transform: scaleY(.30); }
42% { transform: scaleY(.68); }
56% { transform: scaleY(.18); }
70% { transform: scaleY(.80); }
84% { transform: scaleY(.24); }
100% { transform: scaleY(.10); }
}
// 대역 이름도 같은 박자로 바뀐다. 글자 교체는 steps(1, end) 로 한 프레임에 컷 —
// 미리보기 전용 글자는 color: transparent 로만 감춘다 (display: none 은 칸 폭까지 없앤다, 274 실측).
.bs.is-demo .bs__levelText { color: transparent; }
.bs.is-demo .bs__loop { visibility: visible; }
.bs.is-demo .bs__loop i {
animation-name: bsBandName; animation-duration: $dur-loop; animation-timing-function: steps(1, end);
animation-iteration-count: infinite;
// 여기만 fill-mode 를 두지 않는다 — 양수 지연 구간에 backwards 를 쓰면 세 글자가 한꺼번에 보인다.
// 작성 상태가 이미 visibility: hidden 이라 지연 동안 그대로 숨어 있는 게 맞다 (실측: poster 에 세 글자가 겹쳐 찍혔다)
}
.bs.is-demo .bs__loop i:nth-child(1) { animation-delay: 0ms; }
.bs.is-demo .bs__loop i:nth-child(2) { animation-delay: 666ms; }
.bs.is-demo .bs__loop i:nth-child(3) { animation-delay: 1332ms; }
@keyframes bsBandName {
0%, 33% { visibility: visible; }
34%, 100% { visibility: hidden; }
}
@media (max-width: 340px) {
.bs { gap: $sp-2; }
.bs__bars { height: 76px; gap: 0; }
.bs__bar { border-radius: 0; }
.bs__foot { gap: $sp-2; }
.bs__play { padding: $sp-1 $sp-3; }
}
// reduce 에서는 루프를 멈추되 막대를 눕히지 않는다 — 구간 번호로 대칭 스펙트럼 한 장을 세워 둔다
@media (prefers-reduced-motion: reduce) {
.bs.is-demo .bs__bar,
.bs.is-demo .bs__loop i { animation: none !important; }
.bs.is-demo .bs__bar { transform: scaleY(calc(.25 + var(--i) * .045)) !important; }
.bs.is-demo .bs__levelText { color: $subject-cream !important; }
.bs.is-demo .bs__loop { visibility: hidden !important; }
.bs__bar { transition: none !important; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #17141a;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.bs {
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
width: 100%;
max-width: 400px;
}
.bs__hint {
display: flex;
align-items: center;
gap: 4px;
margin: 0;
font-weight: 700;
font-size: clamp(11px, 3vw, 12px);
color: #fff7e6;
}
.bs__ico {
width: 16px;
height: 16px;
color: #ffd23f;
}
.bs__bars {
display: grid;
grid-template-columns: repeat(32, 1fr);
gap: 4px;
align-items: end;
width: 100%;
height: 104px;
}
.bs__bar {
height: 100%;
border-radius: 4px;
background: linear-gradient(180deg, #4cd4a6 0%, #ffd23f 60%, #cdb599 100%);
transform-origin: bottom center;
transform: scaleY(var(--h, 0.08));
transition: transform 220ms ease-out;
}
.bs__foot {
display: flex;
align-items: center;
justify-content: center;
gap: 16px;
width: 100%;
}
.bs__play {
display: inline-flex;
align-items: center;
gap: 4px;
border: 0;
border-radius: 999px;
padding: 8px 16px;
background: #ffd23f;
color: #17141a;
cursor: pointer;
font-family: inherit;
font-weight: 800;
font-size: clamp(11px, 3vw, 12px);
line-height: 1;
}
.bs__ico--pause {
display: none;
}
.bs__play[aria-pressed=true] .bs__ico--play {
display: none;
}
.bs__play[aria-pressed=true] .bs__ico--pause {
display: inline-block;
}
.bs__play .bs__ico {
color: #17141a;
}
.bs__level {
margin: 0;
display: flex;
align-items: center;
gap: 8px;
}
.bs__levelLabel {
font-weight: 700;
font-size: clamp(10px, 2.6vw, 11px);
color: rgba(255, 247, 230, 0.82);
}
.bs__levelBox {
position: relative;
display: grid;
place-items: center;
min-width: 40px;
height: 20px;
border-radius: 4px;
padding: 0 4px;
background: rgba(255, 247, 230, 0.16);
color: #fff7e6;
font-weight: 800;
font-size: clamp(11px, 3vw, 12px);
line-height: 1;
}
.bs__loop {
position: absolute;
inset: 0;
display: grid;
place-items: center;
visibility: hidden;
}
.bs__loop i {
grid-area: 1/1;
font-style: normal;
visibility: hidden;
}
.bs.is-demo .bs__bar {
animation-name: bsWave;
animation-duration: 2s;
animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
animation-iteration-count: infinite;
animation-fill-mode: backwards;
animation-delay: calc(var(--i) * -56ms);
transition: none;
}
@keyframes bsWave {
0% {
transform: scaleY(0.1);
}
14% {
transform: scaleY(0.92);
}
28% {
transform: scaleY(0.3);
}
42% {
transform: scaleY(0.68);
}
56% {
transform: scaleY(0.18);
}
70% {
transform: scaleY(0.8);
}
84% {
transform: scaleY(0.24);
}
100% {
transform: scaleY(0.1);
}
}
.bs.is-demo .bs__levelText {
color: transparent;
}
.bs.is-demo .bs__loop {
visibility: visible;
}
.bs.is-demo .bs__loop i {
animation-name: bsBandName;
animation-duration: 2s;
animation-timing-function: steps(1, end);
animation-iteration-count: infinite;
}
.bs.is-demo .bs__loop i:nth-child(1) {
animation-delay: 0ms;
}
.bs.is-demo .bs__loop i:nth-child(2) {
animation-delay: 666ms;
}
.bs.is-demo .bs__loop i:nth-child(3) {
animation-delay: 1332ms;
}
@keyframes bsBandName {
0%, 33% {
visibility: visible;
}
34%, 100% {
visibility: hidden;
}
}
@media (max-width: 340px) {
.bs {
gap: 8px;
}
.bs__bars {
height: 76px;
gap: 0;
}
.bs__bar {
border-radius: 0;
}
.bs__foot {
gap: 8px;
}
.bs__play {
padding: 4px 12px;
}
}
@media (prefers-reduced-motion: reduce) {
.bs.is-demo .bs__bar,
.bs.is-demo .bs__loop i {
animation: none !important;
}
.bs.is-demo .bs__bar {
transform: scaleY(calc(0.25 + var(--i) * 0.045)) !important;
}
.bs.is-demo .bs__levelText {
color: #fff7e6 !important;
}
.bs.is-demo .bs__loop {
visibility: hidden !important;
}
.bs__bar {
transition: none !important;
}
}var root = document.getElementById('bs');
var barBox = document.getElementById('bars');
var playBtn = document.getElementById('play');
var playLabel = document.getElementById('playLabel');
var levelText = document.getElementById('levelText');
var BAR_COUNT = 32, HALF = BAR_COUNT / 2;
var bars = [];
// 좌우 대칭: 오른쪽 절반은 0..15, 왼쪽 절반은 그 거울상이라 두 막대가 같은 주파수 구간을 쓴다.
// --i 는 그 구간 번호이자 미리보기 루프의 음수 지연 배수다.
for (var i = 0; i < BAR_COUNT; i++) {
var bar = document.createElement('span');
var band = i < HALF ? HALF - 1 - i : i - HALF;
bar.className = 'bs__bar';
bar.style.setProperty('--i', String(band));
bar.setAttribute('data-band', String(band));
barBox.appendChild(bar);
bars.push(bar);
}
var ctx = null, analyser = null, freq = null, timer = 0, playing = false;
var BAND_NAMES = ['Bass', 'Mid', 'Treble'];
function buildAudio() {
ctx = new (window.AudioContext || window.webkitAudioContext)();
analyser = ctx.createAnalyser();
analyser.fftSize = 64;
analyser.smoothingTimeConstant = 0.72;
freq = new Uint8Array(analyser.frequencyBinCount);
var out = ctx.createGain();
out.gain.value = 0.06;
out.connect(analyser);
analyser.connect(ctx.destination);
// 외부 음원 파일 없이 코드 진행을 직접 합성한다 — 네 박자마다 화음이 바뀐다.
[196, 246.94, 293.66, 392].forEach(function (hz, n) {
var osc = ctx.createOscillator();
var amp = ctx.createGain();
osc.type = n === 3 ? 'triangle' : 'sawtooth';
osc.frequency.value = hz;
amp.gain.value = 0;
for (var beat = 0; beat < 64; beat++) {
var at = ctx.currentTime + beat * 0.5;
amp.gain.setValueAtTime(beat % 4 === n % 4 ? 0.9 : 0.25, at);
amp.gain.exponentialRampToValueAtTime(0.02, at + 0.45);
}
osc.connect(amp); amp.connect(out); osc.start();
});
}
function draw() {
analyser.getByteFrequencyData(freq);
var sums = [0, 0, 0];
for (var i = 0; i < bars.length; i++) {
var band = Number(bars[i].getAttribute('data-band'));
var v = freq[band + 1] / 255;
bars[i].style.setProperty('--h', (0.06 + v * 0.94).toFixed(3));
sums[Math.min(2, Math.floor(band / 6))] += v;
}
var top = sums.indexOf(Math.max(sums[0], sums[1], sums[2]));
if (levelText.textContent !== BAND_NAMES[top]) { levelText.textContent = BAND_NAMES[top]; }
timer = requestAnimationFrame(draw);
}
playBtn.addEventListener('click', function () {
root.classList.remove('is-demo');
if (!ctx) { buildAudio(); }
playing = !playing;
playBtn.setAttribute('aria-pressed', playing ? 'true' : 'false');
playLabel.textContent = playing ? 'Stop' : 'Play';
// 자동재생 정책: AudioContext 는 사용자 제스처 뒤 resume() 해야 소리가 난다.
if (playing) { ctx.resume(); timer = requestAnimationFrame(draw); }
else { ctx.suspend(); cancelAnimationFrame(timer); }
});// BarSpectrum — vanilla 판(run/291/demo/01-audio-viz-bar-spectrum/index.html) 의 React 포트.
// 주파수 구간 하나가 막대 하나. 재생 버튼을 누르면 합성 음원을 만들어 AnalyserNode 값으로 막대를 세운다.
import { useEffect, useRef, useState } from "react";
import type { CSSProperties } from "react";
import styles from "./BarSpectrum.module.scss";
export type BarSpectrumProps = {
/** 격자 미리보기용 2초 자동 루프. 재생을 누르면 꺼진다 */
demo?: boolean;
duration?: number;
easing?: string;
color?: string;
};
type Vars = CSSProperties & { "--duration"?: string; "--easing"?: string; "--color"?: string };
type BarVars = CSSProperties & { "--i"?: string; "--h"?: string };
/** ambient 타입에 useRef<T> 의 null 합집합이 없어 로컬로 좁힌다 */
type Box<T> = { current: T };
const BAR_COUNT = 32;
const HALF = BAR_COUNT / 2;
const BAND_NAMES = ["저음", "중음", "고음"];
/** 좌우 대칭: 오른쪽 절반은 0..15, 왼쪽 절반은 그 거울상이라 두 막대가 같은 구간을 쓴다 */
const BANDS: number[] = [];
for (let i = 0; i < BAR_COUNT; i++) {
BANDS.push(i < HALF ? HALF - 1 - i : i - HALF);
}
export default function BarSpectrum({
demo = true,
duration = 220,
easing = "cubic-bezier(.2, .8, .2, 1)",
color = "#ffd23f",
}: BarSpectrumProps) {
const [live, setLive] = useState(demo);
const [playing, setPlaying] = useState(false);
const [heights, setHeights] = useState<number[]>([]);
const [band, setBand] = useState(BAND_NAMES[0]);
const ctxBox = useRef(null) as Box<AudioContext | null>;
const nodeBox = useRef(null) as Box<AnalyserNode | null>;
const frameBox = useRef(0) as Box<number>;
const vars: Vars = { "--duration": `${duration}ms`, "--easing": easing, "--color": color };
useEffect(() => {
return () => {
cancelAnimationFrame(frameBox.current);
if (ctxBox.current) {
ctxBox.current.close();
}
};
}, []);
function buildAudio() {
const ctx = new AudioContext();
const analyser = ctx.createAnalyser();
analyser.fftSize = 64;
analyser.smoothingTimeConstant = 0.72;
const out = ctx.createGain();
out.gain.value = 0.06;
out.connect(analyser);
analyser.connect(ctx.destination);
// 외부 음원 파일 없이 코드 진행을 직접 합성한다 — 네 박자마다 화음이 바뀐다.
[196, 246.94, 293.66, 392].forEach((hz, n) => {
const osc = ctx.createOscillator();
const amp = ctx.createGain();
osc.type = n === 3 ? "triangle" : "sawtooth";
osc.frequency.value = hz;
amp.gain.value = 0;
for (let beat = 0; beat < 64; beat++) {
const at = ctx.currentTime + beat * 0.5;
amp.gain.setValueAtTime(beat % 4 === n % 4 ? 0.9 : 0.25, at);
amp.gain.exponentialRampToValueAtTime(0.02, at + 0.45);
}
osc.connect(amp);
amp.connect(out);
osc.start();
});
ctxBox.current = ctx;
nodeBox.current = analyser;
}
function draw() {
const analyser = nodeBox.current;
if (!analyser) {
return;
}
const freq = new Uint8Array(analyser.frequencyBinCount);
analyser.getByteFrequencyData(freq);
const sums = [0, 0, 0];
const next = BANDS.map((b) => {
const v = freq[b + 1] / 255;
sums[Math.min(2, Math.floor(b / 6))] += v;
return 0.06 + v * 0.94;
});
setHeights(next);
setBand(BAND_NAMES[sums.indexOf(Math.max(sums[0], sums[1], sums[2]))]);
frameBox.current = requestAnimationFrame(draw);
}
function toggle() {
setLive(false);
if (!ctxBox.current) {
buildAudio();
}
const ctx = ctxBox.current;
if (!ctx) {
return;
}
const next = !playing;
setPlaying(next);
// 자동재생 정책: AudioContext 는 사용자 제스처 뒤 resume() 해야 소리가 난다.
if (next) {
ctx.resume();
frameBox.current = requestAnimationFrame(draw);
} else {
ctx.suspend();
cancelAnimationFrame(frameBox.current);
}
}
const cls = [styles.root, live ? styles.isDemo : ""].filter(Boolean).join(" ");
return (
<main className={styles.stage} style={vars}>
<svg width="0" height="0" style={{ position: "absolute" }} aria-hidden="true">
<defs>
<symbol id="ico-waveform" viewBox="0 0 256 256" fill="currentColor">
<path d="M208 96v64H48V96Z" opacity=".2" />
<path d="M56 96v64a8 8 0 0 1-16 0V96a8 8 0 0 1 16 0m32-72a8 8 0 0 0-8 8v192a8 8 0 0 0 16 0V32a8 8 0 0 0-8-8m40 32a8 8 0 0 0-8 8v128a8 8 0 0 0 16 0V64a8 8 0 0 0-8-8m40 32a8 8 0 0 0-8 8v64a8 8 0 0 0 16 0V96a8 8 0 0 0-8-8m40-16a8 8 0 0 0-8 8v96a8 8 0 0 0 16 0V72a8 8 0 0 0-8-8" />
</symbol>
<symbol id="ico-play" viewBox="0 0 256 256" fill="currentColor">
<path d="M228.23 134.69L84.15 222.81A8 8 0 0 1 72 216.12V39.88a8 8 0 0 1 12.15-6.69l144.08 88.12a7.82 7.82 0 0 1 0 13.38" opacity=".2" />
<path d="M232.4 114.49L88.32 26.35a16 16 0 0 0-16.2-.3A15.86 15.86 0 0 0 64 39.87v176.26A15.94 15.94 0 0 0 80 232a16.07 16.07 0 0 0 8.36-2.35l144.04-88.14a15.88 15.88 0 0 0 0-27.02M80 215.94V40l143.83 88Z" />
</symbol>
<symbol id="ico-pause" viewBox="0 0 256 256" fill="currentColor">
<path d="M208 48v160a8 8 0 0 1-8 8h-40a8 8 0 0 1-8-8V48a8 8 0 0 1 8-8h40a8 8 0 0 1 8 8M96 40H56a8 8 0 0 0-8 8v160a8 8 0 0 0 8 8h40a8 8 0 0 0 8-8V48a8 8 0 0 0-8-8" opacity=".2" />
<path d="M200 32h-40a16 16 0 0 0-16 16v160a16 16 0 0 0 16 16h40a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16m0 176h-40V48h40zM96 32H56a16 16 0 0 0-16 16v160a16 16 0 0 0 16 16h40a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16m0 176H56V48h40z" />
</symbol>
</defs>
</svg>
<div className={cls}>
<p className={styles.hint}>
<svg className={styles.ico} aria-hidden="true">
<use href="#ico-waveform" />
</svg>
<span>재생을 누르면 실제 소리로 움직입니다</span>
</p>
<div className={styles.bars} aria-hidden="true">
{BANDS.map((b, i) => {
const barVars: BarVars = { "--i": String(b) };
if (heights[i] !== undefined) {
barVars["--h"] = heights[i].toFixed(3);
}
return <span className={styles.bar} key={i} style={barVars} />;
})}
</div>
<div className={styles.foot}>
<button className={styles.play} type="button" aria-pressed={playing} onClick={toggle}>
<svg className={[styles.ico, playing ? styles.icoHidden : ""].join(" ")} aria-hidden="true">
<use href="#ico-play" />
</svg>
<svg className={[styles.ico, playing ? "" : styles.icoHidden].join(" ")} aria-hidden="true">
<use href="#ico-pause" />
</svg>
<span>{playing ? "정지" : "재생"}</span>
</button>
<p className={styles.level}>
<span className={styles.levelLabel}>센 대역</span>
<b className={styles.levelBox}>
<span className={styles.levelText} aria-live="polite">
{band}
</span>
<span className={styles.loop} aria-hidden="true">
<i>저음</i>
<i>중음</i>
<i>고음</i>
</span>
</b>
</p>
</div>
</div>
</main>
);
}01 Bar spectrum — Measured area 19.231% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · Audio Visualizer JavaScript: 9 Parts, No Library
The post this demo lives in
Audio Visualizer JavaScript: 9 Parts, No LibraryAn audio visualizer JavaScript project needs one thing from the browser: Web Audio's AnalyserNode, which turns live soun See all demos in this post


