0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Play/pause control for animated images. Add data-effect='animate-image' to any GIF, WebP or APNG for a pause button that really stops the animation, reduced-motion support and picture/srcset support.
Overview
The data-effect="animate-image" effect adds a pause/play button to an animated image (GIF, animated WebP or APNG). Pausing shows a still image, so readers can stop distracting motion (WCAG 2.2.2 Pause, Stop, Hide). The image starts paused when the reader prefers reduced motion.
It is part of the unified effects system and ships in the effects pack. There is no bare data-animate-imageattribute: always write data-effect="animate-image".
Basic usage
12
<imgsrc="robot-arm.gif"data-effect="animate-image"alt="A robot arm picks up a block and sets it down again">
Usage
The effect wraps the image — or its whole <picture>, so the <source> elements keep applying — in a <span class="animate-image-wrapper"> and adds a <button class="animate-image-toggle"> in its corner.
What "paused" shows, in order:
data-poster, when you give one: a still image URL.
Otherwise the first frame, captured to a canvas once the image loads. While paused, srcset / sizes on the image and its <source>s are set aside and restored on play.
If no frame can be captured — a cross-origin image served without CORS headers taints the canvas — pausing hides the animation and shows its alt text in its place. The button never claims "paused" while the image keeps moving. Give cross-origin images a data-poster (or crossorigin plus CORS headers) to get a still instead.
Do not put the image inside a link: the button would be nested inside the link, which is invalid and confusing for keyboard users.
On an <img> (optionally inside <picture>). Adds the control.
data-poster
URL
Still image shown while paused. Recommended for cross-origin images.
data-animate-image-paused
boolean
Start paused. Also reflected by the effect while the image is paused.
data-label-animation-pause
string
Button name (default "Pause animation"). The alt text is appended ("Pause animation: A robot arm…"), or placed where you write {alt}. Read from the image or any ancestor, so one attribute on <html> localises every image.
Styling
.animate-image-wrapper — the inline-block positioning box. [data-animate-image-hidden] is set on it while a paused image is hidden.
.animate-image-toggle — the round button; [aria-pressed="true"] shows the play triangle. Forced-colors mode uses system button colours.
.animate-image-placeholder — the alt-text box shown when the animation is hidden.
img[data-animate-image-paused] — the image while paused.
Reduced motion
The image starts paused when either is true, and both are watched while the page is open:
prefers-reduced-motion: reduce — the operating-system setting;
<html data-motion-reduced> — set by <settings-panel> when the reader turns motion effects off.
Turning reduced motion on pauses every playing image; turning it off resumes the ones it paused (not the ones the reader paused). The reader can always press play.
Accessibility
The button keeps one name and reports its state with aria-pressed ("Pause animation: <alt>", pressed = paused), so several animated images on a page are distinguishable.
Alt text: describe what the animation shows (“A robot arm picks up a block and sets it down again”), not the format (“GIF”) or a placeholder (“Demo”). An image without alt logs a console warning.
Pausing really stops the motion: a still, or the animation hidden behind its alt text (WCAG 2.2.2).
The button is a native <button>: focusable, activated with Enter or Space, with a visible focus ring.
Without JavaScript the image displays normally.
Examples
Start paused, poster, picture
Options
1234567891011
<imgsrc="robot-arm.gif"data-effect="animate-image"data-animate-image-pausedalt="A robot arm picks up a block and sets it down again"><!-- Cross-origin GIF: give it a still --><imgsrc="https://cdn.example.com/loop.gif"data-poster="/img/loop-still.png"data-effect="animate-image"alt="Our logo spins once and settles"><picture><sourcesrcset="wide.gif"media="(min-width: 40rem)"><imgsrc="narrow.gif"data-effect="animate-image"alt="A ball bounces across the frame"></picture>
Dynamic elements
Images added later are enhanced by the effects runtime; a clone of an enhanced image (even a paused one) gets its own working control.
Added later
12345
const img = document.createElement('img');img.src = 'animation.gif';img.alt = 'A paper plane loops across the page';img.dataset.effect = 'animate-image';document.querySelector('main').append(img);
Related
data-effect — the effects system and its other effects.
<video> — which to choose: for anything longer than a short loop, a muted <video> with controls is smaller than a GIF and has native pause; use animate-image when you must ship an animated image.