Back to Snippets

AI Voice Command Ripple Canvas JS

Press and hold the mic button and expanding rings pulse out from its center. Release and the rings already in flight finish traveling and fade out.

A ripple spawns every 120 milliseconds while the button is held. Each one reads the button's live getBoundingClientRect for its center and starts at the button radius, so rings emerge from the edge of the button instead of a hardcoded point. That keeps them aligned after a resize or a scroll rather than drifting off.

setPointerCapture on pointerdown means the release still registers if you drag off the button first, and pointercancel is handled too, so a browser gesture cannot leave the button stuck in the listening state. Ring speed is randomized a little per ripple, which reads as sound modulation instead of a mechanical pulse.

144
#javascript
#css
#canvas
#ripples
#voice
#microphone
#animation
#interaction
#ui