DocsThe iconMotion and hover
Motion and hover
Each icon has its own small motion. Two classes decide when it plays.
Press play, or drag through the fidget frame by frame.
#On hover
| Class | What a hover does |
|---|---|
fidg-hover | Plays the icon: its motion, and its value swept away from rest and back. |
fidg-move | Plays only the motion. Use it when the value means something and must stay put. |
Put the class on the icon, or on any parent such as a button, a link or a card. Both classes answer keyboard focus too, so nothing is hover-only.
<a class="fidg-hover" href="/cart">
<svg class="fidg" viewBox="0 0 24 24">…</svg> Cart
</a>
<!-- a battery that shows a real charge: move, never sweep -->
<span class="fidg-move"><svg class="fidg" style="--v: .3">…</svg></span>#On click, on a timer, on anything
Add is-on next to fidg-hover on the parent and the fidget plays now. Take it off again when the fidget ends: while is-on stays, the icon holds its rest value and ignores --v.
function fidget(el) {
el.classList.remove('is-on');
void el.offsetWidth; // let the browser see the change
el.classList.add('is-on');
setTimeout(() => el.classList.remove('is-on'), 1100); // a fidget lasts 1.1 seconds
}
saveButton.addEventListener('click', () => fidget(saveButton));#Hold a moment
A fidget lasts 1.1 seconds. To hold it at one moment, for a loader, a scroll effect or a screenshot, add fidg-scrub next to fidg-hover is-on and set --t in seconds.
<span class="fidg-hover is-on fidg-scrub" style="--t: .4">
<svg class="fidg" viewBox="0 0 24 24">…</svg>
</span>#Reduced motion
Visitors whose device asks for reduced motion see no motion at all. Values still change. To make them jump instead of glide too, set --fidg-glide: 0s in the same media query. To offer your own switch, put fidg-calm on <html> or any part of the page.
@media (prefers-reduced-motion: reduce) {
.fidg { --fidg-glide: 0s; }
}