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.
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
- Each clock and each sign is a
drawablechild of the canvas. - Count the
paintevents that name each clock, and place its notch and sign from the count. - Tell a clock's paint events from the others.
- The paint handler. It has no frame loop.
- 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.
- The clock stays still. Drawing an element at a new place raises a
paintevent that names it. Each clock is drawn at the same place every time, and the part that moves, the sign, is a separatedrawableelement, so the events of a swinging sign aren't counted as frames. - Formats that aren't an
<img>. The inline SVG and the CSS background are inside adrawable<div>. The event names the div. - Restart. The buttons set each image's address again with a new query string, which starts the animation from its first frame. The inline SVG is reset with
setCurrentTime(0). - Lottie isn't here. A Lottie file isn't an image format that the browser animates. A player script changes an inline SVG or a canvas from
requestAnimationFrame(), so its clock is the script's frame loop, and this site has no player library.
Show the code
- The demo starts when its section comes near the screen.
- A lost context stops the drawing.
- 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.
- Every frame-based format raised one
paintper frame. GIF, APNG, WebP and AVIF in an<img>each gave 12.5 paint events a second for files of 12.5 frames a second. So did an SVG file with a stepped SMIL animation and one with a stepped CSS animation. - The image doesn't have to be an
<img>. A GIF as a CSSbackground-image, a<picture>that chose its AVIF source, an<object>that loaded the SVG file and a div withcontent: url(clock.gif)gave 12.5 a second. The event names thedrawableelement that holds the image. - An inline SVG with the same stepped SMIL animation gave a less even count. 9.4 a second in the live check's canvas in three runs, and 12 to 15 in the demo. The animation is sampled by the page's own frames, not by an image decoder.
- A continuous animation has no frame rate. The SVG whose dot turns smoothly raised 59.4 events a second, one for each frame of a 60 Hz display, so an effect that counts its events runs about five times faster than one that counts the frames of a GIF.
- A finished animation is a stopped clock. A GIF with a loop count of one raised 13 events for its 12 frames and none in the second after. Setting its address again with a new query string played it again.
- Two images in one canvas are named separately. A GIF and an APNG in one canvas were each named 12.5 times a second in
changedElements, in 12.5 paint events a second: frames that fall in the same display frame share one event. - An SVG file in an
<img>stops when the place it is drawn at is off screen. With the canvas scrolled above the window for 2.3 s, both stepped SVG files and the smooth one showed 0 events in the last second. The four raster formats, the inline SVG and the CSS background carried on at 12 to 13, and the handler ran 55 times while the canvas couldn't be seen. With only the lower rows of the canvas on screen, the SVG files in the rows above stopped and the one below ran, so the test is the drawn place of the image, not the place of the canvas. - Not built: Lottie. It is a script that animates an inline SVG or a canvas from
requestAnimationFrame(), not an image format, and this site has no player library. - Not verified: everything on a phone. In particular whether Chrome on Android decodes all four raster formats at the stored rate, whether it pauses raster images when the canvas is off screen (the line under the demo counts those events), and the rate of the smooth SVG on a 90 or 120 Hz display.