When icons play
On hover, on click, on mount, or when your code says so.
| animate | Plays |
|---|---|
hover | When the pointer enters the icon’s button or link (or the icon), and on keyboard focus. The default. |
click | When the button, link or icon is clicked or tapped |
mount | Once, as soon as it appears |
none | Only when you call play(), below |
The control around it
By default an icon plays when the control around it does something. It listens on the nearest button, link, label or [role=button] around it, so you never wire anything up:
<button><Gift variant="solid" /> Open gift</button> {/* hovering the button plays the gift */}Each icon here sits inside a button.
Play on click
<button><Send animate="click" sound /> Send</button>Play from anywhere
Set animate="none" and call play() on a ref, for example when a save finishes:
const saved = useRef(null);
async function save() {
await api.save(draft);
saved.current.play();
}
return <>
<Saved ref={saved} animate="none" sound />
<button onClick={save}>Save</button>
</>;In Vue, call play() on a template ref. Without a framework, call play(element, icon) from jiggicons, or element.play() on a <jigg-icon>.
Mark a different trigger
Add data-jiggicon-trigger to any element to make it the one the icon listens on, such as a whole card:
<article data-jiggicon-trigger>
<Rocket /> Launch week
</article>