Animated image formats as paint clocks

Paint clocks found that an animated GIF in a drawable canvas raises paint once for each of its frames. I wanted to know if the same is true of the other ways to put an animated image in a page. Every file here shows the same spinner: 12 frames of 80 ms, which is 12.5 frames a second. Each is a drawable child of one canvas, and the canvas counts the paint events that name it. Nothing on the page calls requestAnimationFrame() or starts a timer.

Ten clocks, each with a sign hanging from it. The canvas draws the ring of notches and moves the lit notch on by one place for each paint event that names the clock inside it, so the lit notch goes round at the speed of the orange dot in the image. The sign swings through one cycle in 12 events. Signs that swing together have clocks that raise events at the same rate. The number beside each clock is its count for the last second.

Spinner, GIF Spinner, APNG Spinner, WebP Spinner, AVIF Spinner, SVG with a stepped SMIL animation
SVG, SMIL stepssmil.svg
Spinner, SVG with a stepped CSS animation
SVG, CSS stepscss.svg
Inline SVGSMIL, in the page
CSS backgroundbackground-image
Spinner, GIF that plays once
GIF, plays onceonce.gif
Spinner, SVG with a continuous SMIL animation
SVG, smooth SMILsmooth.svg

The GIF that plays once swings its sign through one cycle and stops, because a finished image raises no more events. The smooth SVG has no frames: its dot turns continuously, so it raises an event for every frame the display shows and its sign swings several times faster than the others. The line above also counts the events that arrive while this canvas is scrolled off screen. Scroll down, wait, and scroll back to read it.

Show the code
  1. Each clock and each sign is a drawable child of the canvas.
  2. Count the paint events that name each clock, and place its notch and sign from the count.
  3. Tell a clock's paint events from the others.
  4. The paint handler. It has no frame loop.
  5. Styles.

How it works

A drawable canvas gets a paint event when the picture of one of its drawable descendants changes, and event.changedElements lists the descendants that changed. When an animated image shows its next frame the element's picture changes, so the image is in that list. The handler on this page redraws the whole canvas on every event and adds one to a tile's count when the list holds that tile's clock.

Show the code
  1. The demo starts when its section comes near the screen.
  2. A lost context stops the drawing.
  3. The elements are then shown as plain HTML.

Live checks

The checks wait for a tap and take about 20 seconds, because each one counts paint events for a second or more. Each builds its own small canvases in a corner of the window, and none of them touches the demo above.

Findings

Measured in headless Chromium 157 on 2026-11-21. Not yet run on a phone.