DocsThe iconSound
Sound
An optional module of 86 short sounds, built in the browser as they play. Nothing is downloaded, and nothing plays until a visitor says so.
#Switch it on
import { createSound } from 'fidgicons/sound';
const sound = createSound();
toggle.onclick = () => sound.set(!sound.on); // remembered for next time
button.onpointerenter = () => sound.play('coin');Browsers only allow sound after a click, tap or key press, so call sound.set(true) from one. The choice is remembered on that browser; sound.remembered() tells you it was switched on before.
#Every sound
Each icon in index.json names its sound. Tap one to hear it.
#Place it between the speakers
A sound can start where its icon is and travel. The fifth argument is the place, from -1 (left) to 1 (right); the sixth is how far it moves while it plays.
const x = (el.getBoundingClientRect().left / innerWidth) * 2 - 1;
sound.play('engine', 1, 0, false, x, 0.7); // starts where the icon is, drives right| Argument | What it sets |
|---|---|
name | One of the 86 sounds above. |
pitch | Multiplies the pitch. 1 is as made. |
delay | Seconds to wait. |
force | true plays even while sound is off. Keep it for a sound the visitor asked to hear. |
pan | -1 left, 0 centre, 1 right. |
travel | How far the sound moves while it plays. |
Something missing or unclear?Write to usRequest an icon