Paint clocks

Four ideas from the element catalogue. Some elements repaint by themselves: an indeterminate progress bar, a blinking caret, a playing video, an animated image. Each repaint raises paint on the canvas that holds the element. On this page that event is the only clock. No demo calls requestAnimationFrame(), starts a timer or asks for paints in a loop, so each effect runs at the rate of its element and stops when the element stops. The line under each canvas counts the paint events.

Loading state that stops by itself

A <progress> bar above an article. Press Start loading: the bar loses its value, its stripes move, and the article sways, grey and blurred, under a band of light. Press Finish: the bar gets a value, and the drawing stops with the finished article.

loaded

Tide table, Thursday

Times for the harbour gauge. Heights are above chart datum.

High04:125.1 m
Low10:310.9 m
High16:405.3 m

Nothing has to be cancelled when loading ends. The page has no loop to stop: the bar stops repainting, so paint stops. The stripes are a CSS animation on the bar. The browser's own indeterminate bar repaints too, at a lower rate, which the live checks measure.

Show the code
  1. The bar and the article are drawable children of the canvas.
  2. Draw the loading effect on each paint while the bar has no value.
  3. Styles. The stripes are a CSS animation on the bar.

Caret as a heartbeat

Tap the field. The caret blinks, and each time it goes on or off the card beats and the trace moves one step. Type, and each letter adds a beat. Tap outside the field and the trace goes flat and stops.

Not focused: no caret, so no paint events. Tap the field.

The card has two states and no animation between them, because between two blinks nothing raises paint. The time between paint events printed above is the caret's blink interval on this device.

Show the code
  1. The card and the field are separate drawable children, so the field can stay still while the card beats.
  2. Treat each paint that the field raised as half a beat.
  3. Tell the clock's paint events from the others.
  4. Styles.

Video as a frame clock for a whole scene

Press Play. The video is drawn in the canvas, and the three cards and the credits are placed from video.currentTime each time the video shows a new frame. Pause, and everything holds. Drag the slider while paused, and the whole scene moves to that moment.

Scene 1Harbour
Scene 2Sea wall
Scene 3Lighthouse
  • ClockThe video element
  • FramesOne paint event each
  • TimersNone
  • Animation framesNone
  • Positionvideo.currentTime

The scene can't run ahead of the film or behind it, because it has no time of its own. A stalled video stalls the scene, and a seek is a seek for everything.

Show the code
  1. The video, the cards and the credits are drawable children of the canvas.
  2. Place everything from currentTime on each paint.
  3. Styles.

Animated image as the only clock

The spinner is an animated GIF of 12 frames. Each frame of it moves the wave in the flag by one step. Swap in the slow file and the flag slows down by the same factor. Remove the image and the flag stops. The checkbox gives the image opacity: 0, to see whether a clock that can't be seen still runs.

Spinner, the clock for this canvas

Regatta, Saturday

First gun at 10:30. Course cards at the club house.

How this page is drawn

The handler counts paint events and never reads the time, so the frame delay stored in the image file sets the speed of the scene. A clock that shouldn't be seen can be left out of the drawing: the image raises paint whether or not the handler draws it.

Show the code
  1. The image and the flag are drawable children of the canvas.
  2. Move the wave one step on each paint.
  3. Styles.

How it works

A drawable canvas gets a paint event when the picture of one of its drawable descendants changes. An element that animates by itself therefore raises a steady run of paint events, at its own rate, for as long as it animates. Each demo has one paint handler and nothing else that runs over time:

Show the code
  1. The paint handler shared by the four demos. It has no frame loop.
  2. Each demo starts when its section comes near the screen.
  3. A lost context stops every demo.
  4. The elements are then shown as plain HTML.

Live checks

The checks wait for a tap and take about 25 seconds, because each one counts paint events for a second or more. Each builds its own small canvas in a corner of the window, and none of them touches the demos above. The caret isn't checked here, because a check must not move focus: its rate is printed under the heartbeat demo.

Findings

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