Skip to content

176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.

fix: Audio Visualizer review: bar-only settings hidden under Wave, the legend's dots stay with their words, Pause keeps the analyzer's last line, the Colors hint true for Wave

matin5c36af664762
diff --git a/animations/06-3d-advanced/audio-visualizer/README.md b/animations/06-3d-advanced/audio-visualizer/README.md
index 5b920f8d..ae8b582f 100644
--- a/animations/06-3d-advanced/audio-visualizer/README.md
+++ b/animations/06-3d-advanced/audio-visualizer/README.md
@@ -36,10 +36,10 @@ The demo plays no file and uses no microphone. Its tune is written in the page a
| Parameter | Default | Effect |
|-----------|---------|--------|
| Style | Bars | Bars stand in a row from bass to treble; wave draws the sound's shape over a few hundredths of a second instead of its pitches; circle sets the bars around a ring that swells with the bass |
-| Number of bars | Many | Few is 16 bars, some 32 and many 64; phones start at some, and each row of Compare holds half as many bars on phones; a wave has no bars, so it ignores this |
-| How bars fall | Gently | How fast a bar sinks after it jumps: quickly is 2.6 bar heights a second, gently 1.2 and slowly 0.45, like an old stereo; a wave ignores it |
-| Peak marks | on | A thin mark (a dot in the ring) holds each bar's highest point for 0.4 seconds, then sinks slowly; off, only the bars show; a wave has none |
-| Colors | Sunset | The colors from the bottom of each bar to its top: sunset runs from coral to gold, ocean from deep blue to cyan, neon from pink to cyan; See inside lays the colors of the tune's parts over them |
+| Number of bars | Many | With Bars or Circle: few is 16 bars, some 32 and many 64; phones start at some, and each row of Compare holds half as many bars on phones; Wave has no bars and hides this setting |
+| How bars fall | Gently | With Bars or Circle, how fast a bar sinks after it jumps: quickly is 2.6 bar heights a second, gently 1.2 and slowly 0.45, like an old stereo; Wave hides this setting |
+| Peak marks | on | With Bars or Circle, a thin mark (a dot in the ring) holds each bar's highest point for 0.4 seconds, then sinks slowly; off, only the bars show; Wave hides this setting |
+| Colors | Sunset | The colors from the bottom of each bar to its top, or from left to right along the wave: sunset runs from coral to gold, ocean from deep blue to cyan, neon from pink to cyan; See inside lays the colors of the tune's parts over them |
## Production notes
- **Ask before sound.** Create the `AudioContext` inside the visitor's own press of play: browsers keep a context made earlier suspended and warn in the console. Never open the microphone without a clear reason and the visitor's yes.
diff --git a/animations/06-3d-advanced/audio-visualizer/index.html b/animations/06-3d-advanced/audio-visualizer/index.html
index dfd6ec1d..044566e2 100644
--- a/animations/06-3d-advanced/audio-visualizer/index.html
+++ b/animations/06-3d-advanced/audio-visualizer/index.html
@@ -36,6 +36,7 @@
.stage[data-hb-mode="inside"] .in:not(.scale),.stage[data-hb-mode="compare"] .row{display:block}
.key{left:10px;top:10px;max-width:calc(100% - 140px);white-space:normal}
.key i{display:inline-block;width:9px;height:9px;margin:0 4px 0 2px;border-radius:50%;vertical-align:0}
+ .key span{white-space:nowrap}
.beat{left:10px;top:var(--beat-y,50px)}
.scale{left:10px;right:10px;bottom:8px}
.stage[data-hb-mode="inside"].st-bars .scale{display:flex;justify-content:space-between}
@@ -70,7 +71,7 @@
<div class="stage st-bars">
<canvas id="cvs" role="img" aria-label="Bars from bass on the left to treble on the right, jumping to a beat and sinking back"></canvas>
<button class="hear" type="button" id="hear" aria-pressed="false"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9v6h4l5 4V5L8 9z"/><path d="M16.5 8.5a5 5 0 0 1 0 7M19 6a8.5 8.5 0 0 1 0 12"/></svg><span>Hear it</span></button>
- <p class="av-lbl in key" aria-hidden="true" data-hb-caption><i style="background:#ff5d5d"></i>Kick <i style="background:#ffa94d"></i>Snare <i style="background:#b07cff"></i>Bass <i style="background:#5cd18a"></i>Melody <i style="background:#4fc3f7"></i>Hi-hats</p>
+ <p class="av-lbl in key" aria-hidden="true" data-hb-caption><span><i style="background:#ff5d5d"></i>Kick</span> <span><i style="background:#ffa94d"></i>Snare</span> <span><i style="background:#b07cff"></i>Bass</span> <span><i style="background:#5cd18a"></i>Melody</span> <span><i style="background:#4fc3f7"></i>Hi-hats</span></p>
<p class="av-lbl in beat" aria-hidden="true" data-hb-caption>The beat</p>
<p class="av-lbl in scale" aria-hidden="true" data-hb-caption><span>Bass</span><span>Middle</span><span>Treble</span></p>
<p class="av-lbl row first" aria-hidden="true" data-hb-caption>Equal slices</p>
@@ -134,7 +135,7 @@
<button type="button" data-pal="ocean" aria-pressed="false">Ocean</button>
<button type="button" data-pal="neon" aria-pressed="false">Neon</button>
</div>
- <p class="hb-hint">The colors from the bottom of each bar to its top.</p>
+ <p class="hb-hint">The colors from the bottom of each bar to its top, or along the wave.</p>
</div>
</div>
</details>
@@ -348,9 +349,12 @@
// Where Compare draws: the top 58px hold Hear it and the first name, then two halves of the same width and height, the second
// name in the band between them
function layout(){const h=Math.max(40,Math.floor((H-58-8-30)/2));return{h,y1:58,y2:58+h+30,l2:58+h+4}}
+ // While the sound plays, Wave draws the analyzer's own line; a context held back (Pause, a hidden tab) keeps the last one it drew
+ let liveWave=null;
function draw(){
ctx.clearRect(0,0,W,H);
- const live=audio&&audio.ctx.state==='running'&&style==='wave'?toWave(audio.an):null;
+ if(audio&&audio.ctx.state==='running')liveWave=toWave(audio.an);
+ const live=audio&&style==='wave'?liveWave:null;
if(mode==='compare'){const L=layout();drawRow(rows.lin,10,L.y1,W-20,L.h,false,song,live);drawRow(rows.cmp,10,L.y2,W-20,L.h,false,song,live);
ctx.fillStyle='rgba(255,255,255,.12)';ctx.fillRect(0,L.y1+L.h+1,W,2)}
else if(mode==='inside'){drawBeat(insideTop+30);drawRow(rows.log,10,insideTop+56,W-20,H-insideTop-96,true,song,live)}
@@ -380,6 +384,7 @@
// The browser answers a start, stop or close with a promise that can fail (a context already closed): nothing to report then
const quiet=p=>{if(p&&p.catch)p.catch(()=>{})};
function startAudio(){
+ liveWave=null;
const ac=new (window.AudioContext||window.webkitAudioContext)(),an=ac.createAnalyser(),out=ac.createGain();
an.fftSize=2048;an.smoothingTimeConstant=.5;out.gain.value=.45;out.connect(an);an.connect(ac.destination);
const noise=ac.createBuffer(1,ac.sampleRate,ac.sampleRate),d=noise.getChannelData(0);for(let i=0;i<d.length;i++)d[i]=Math.random()*2-1;
@@ -452,7 +457,9 @@
pick(b.dataset);notes();if(rows)draw();
}));
}
- choices('style-seg',d=>{style=d.style;stage.classList.toggle('st-bars',style==='bars')});
+ // A wave has no bars, so the settings that only change bars are hidden while Wave is chosen (and out of Your settings)
+ const barOnly=['bars-seg','fall-seg','peak-tog'].map(id=>document.getElementById(id).closest('.hb-setting'));
+ choices('style-seg',d=>{style=d.style;stage.classList.toggle('st-bars',style==='bars');barOnly.forEach(s=>s.hidden=style==='wave')});
choices('bars-seg',d=>{count=+d.n;build()});
choices('fall-seg',d=>{fall=+d.fall});
choices('colors-seg',d=>{pal=d.pal});
diff --git a/skills/animation-handbook/references/06-3d-advanced.md b/skills/animation-handbook/references/06-3d-advanced.md
index a1a23530..afd2fed2 100644
--- a/skills/animation-handbook/references/06-3d-advanced.md
+++ b/skills/animation-handbook/references/06-3d-advanced.md
@@ -610,7 +610,7 @@ Add an audio visualizer to [your music player, podcast card or hero section]. Co
**Settings** (the choice in bold is where the demo starts; each line ends with what the setting does, with the demo's values):
- Style: **Bars** · Wave · Circle. Bars stand in a row from bass to treble; wave draws the sound's shape over a few hundredths of a second instead of its pitches; circle sets the bars around a ring that swells with the bass.
-- Number of bars: Few · Some · **Many** (phones start with Some). Few is 16 bars, some 32 and many 64; phones start at some, and each row of Compare holds half as many bars on phones; a wave has no bars, so it ignores this.
-- How bars fall: Quickly · **Gently** · Slowly. How fast a bar sinks after it jumps: quickly is 2.6 bar heights a second, gently 1.2 and slowly 0.45, like an old stereo; a wave ignores it.
-- Peak marks: **on** · off. A thin mark (a dot in the ring) holds each bar's highest point for 0.4 seconds, then sinks slowly; off, only the bars show; a wave has none.
-- Colors: **Sunset** · Ocean · Neon. The colors from the bottom of each bar to its top: sunset runs from coral to gold, ocean from deep blue to cyan, neon from pink to cyan; See inside lays the colors of the tune's parts over them.
+- Number of bars: Few · Some · **Many** (phones start with Some). With Bars or Circle: few is 16 bars, some 32 and many 64; phones start at some, and each row of Compare holds half as many bars on phones; Wave has no bars and hides this setting.
+- How bars fall: Quickly · **Gently** · Slowly. With Bars or Circle, how fast a bar sinks after it jumps: quickly is 2.6 bar heights a second, gently 1.2 and slowly 0.45, like an old stereo; Wave hides this setting.
+- Peak marks: **on** · off. With Bars or Circle, a thin mark (a dot in the ring) holds each bar's highest point for 0.4 seconds, then sinks slowly; off, only the bars show; Wave hides this setting.
+- Colors: **Sunset** · Ocean · Neon. The colors from the bottom of each bar to its top, or from left to right along the wave: sunset runs from coral to gold, ocean from deep blue to cyan, neon from pink to cyan; See inside lays the colors of the tune's parts over them.