Video, image and chart tiles
Five media ideas from the element catalogue: a <video> drawn as a wall of tiles, a
<figure> whose image goes through an effect while its caption does not, a <picture> whose file is
chosen by the size the canvas draws it at, an SVG chart drawn turned and tilted with its hover styles and links working, and a
script-drawn chart exported with its HTML legend as one PNG. I wanted to know whether each media element keeps its own behaviour
(controls, srcset, :hover, links, checkboxes) when a canvas draws it in pieces, at another size or under a transform.
Video wall
One <video controls> element, drawn as a grid of tiles that drift apart. Move a pointer over the wall or tap it: the tiles close up, and the video's own controls can be used. Four seconds after the last touch the tiles drift again.
Every tile is a source rectangle of the same element, drawn in the same paint handler, so all tiles hold the same video frame. Each such draw moves the video's hit region to that tile. A last draw of the whole video inside an empty clip puts the region back on the closed wall, which is where the controls answer.
Show the code
- Draw one video as tiles, each with its own transform.
- Close the wall while it's used.
- Styles.
Figure with a live caption
A <figure> with an <img> and a <figcaption>. The buttons choose what the canvas does to the image. The caption is drawn on top with no effect: its words can be selected and edited, and its link can be followed.
The figure itself isn't drawn. Its two children carry the drawable attribute, so each has its own picture and its own hit region. The dark panel behind the caption is a third draw of the image, clipped to the caption's box and blurred with ctx.filter.
Show the code
- A figure whose image and caption are each
drawable. - Four effects on the image, then the caption with one plain draw.
- Styles.
Resolution chosen by drawn size
A <picture> with four files, 160 to 1280 pixels wide. Each file has its width written in its top left corner. Move the slider or walk up to the picture: the page writes the drawn width into sizes, and the browser picks the file. The loupe in the corner enlarges the part round the sun, from the same element.
The image is laid out at 160 CSS pixels and is never laid out again. Only sizes changes. The browser goes up through the files as the picture grows and keeps the largest one when it shrinks again. With the box unticked, sizes is written once when the walk ends, and only one file is fetched for it.
Show the code
- A
<picture>with width descriptors. - Write the drawn width into
sizesand draw the image at that width. - List the files that were fetched.
- New URLs, to watch the choice from the start.
- Styles.
SVG chart as a live texture
An inline <svg> bar chart, drawn as a thick sheet that sways. Each bar is a link with a hover style. Point at a bar with a mouse, or tap one: the bar changes colour through its own CSS, and the canvas adds a label that it reads from the chart. Drag sideways to turn the sheet.
A 2D context has affine transforms only, so the sheet is drawn in an orthographic view: a turn, then a squash. That's one matrix, and drawElementImage() gives the same matrix to the hit region. A perspective view would need a mesh of triangles, and the hit region would then follow only the last triangle.
Show the code
- The chart: bars are
<a>elements around a<rect>. - Draw the chart turned and tilted, and read
:hoverin the paint handler. - A tap follows the bar's link.
- Styles: hover, the bar transition and the animated line.
Chart and legend exported as one picture
A ring chart drawn by script into a plain <canvas>, beside an HTML legend of checkboxes, in one <figure>. Untick a row to remove its slice. The outer canvas draws the figure, and one toBlob() call on it gives the chart, the legend and the caption as a PNG.
The inner canvas isn't a drawable canvas. It's content of the figure, like an image, and it is in the figure's picture. The export reads the outer canvas once, on the tap. The picture under the buttons is the exported file.
Show the code
- A figure with a plain canvas, a list of checkboxes and a caption.
- Draw the ring into the inner canvas.
- Draw the figure in the outer canvas and export it with one call.
- Save, copy and share the PNG.
- Styles.
How it works
Each demo is one 2D drawable canvas with one media element in it. The paint handler draws the element with drawElementImage(), and reads what it needs from the element at that moment.
- Media raises
paintby itself. A playing video raises it for each frame, a newly loaded image file raises it once, a CSS animation or transition inside an SVG raises it for each frame, and so does a redraw of a canvas inside a figure. The handlers ask for extra frames only for their own motion. - Pieces come from the nine-argument form.
drawElementImage(el, sx, sy, sw, sh, dx, dy, dw, dh)copies a source rectangle given in CSS pixels of the element. The wall's tiles and the ripple's rows are such pieces. - The last draw decides where input goes. After pieces, the handler draws the whole element once more inside an empty clip. That adds no pixels and puts the hit region where the controls should answer.
- A picture is rastered at the size it is drawn. An element laid out small and drawn large is sharp, so the layout size of an image doesn't limit its drawn size. The file it shows does, which is what
sizesis for.
Show the code
- The paint loop and the draw helpers shared by the five demos.
- Each demo starts when its section comes near the screen.
- A lost context stops every demo.
- The elements are then shown as plain HTML.
Live checks
The checks wait for a tap. Each one builds its own small canvas in a corner of the window, and none of them touches the demos above. Pixels are read from a drawImage() copy, not from the drawable canvas.
Findings
Measured in headless Chromium 157 on 2026-11-21, at 412 px wide with a mouse and emulated touch, at device pixel ratio 1 and 2.625. Not yet run on a phone.
- All five elements kept their own behaviour. The video's controls, the caption's link and editable text, the file choice of
srcset, the chart's:hoverstyle and links, and the legend's checkboxes worked while the canvas drew the element in pieces, at another size or under a turn and a squash. - Pieces of one video drawn in one paint handler hold the same frame. Two copies of one source rectangle differed by 0.00 per channel on average at device pixel ratio 1 and by at most 0.10 at 2.625, while samples 110 ms apart differed by about 11. A playing 30 fps clip raised about 30 paint events a second with no
requestPaint(). - The hit region follows the last draw, so the wall ends with a whole draw in an empty clip. After that draw the video was found at all four corners of the closed wall's box and not at the last tile. With the wall closed and the video paused there were 0 paint events in 0.7 s.
- A touch tap on the closed wall showed the video's own controls (emulated touch). It didn't pause the clip. The page's Pause button calls
pause(). - An
<img>and a<figcaption>are drawn separately when each isdrawableand the figure is not. The image went throughgrayscale(1)and the caption beside it stayed white. The link in the caption was found at its drawn place, and typing into the caption changed its text in the canvas. - Blends and masks reach only what is already on the canvas. Each effect is drawn first on the empty canvas (
multiply,lighten,destination-inwith a dot pattern), the background is added behind withdestination-over, and the caption is drawn last. - An element's picture is rastered at the size it is drawn. A box laid out 20 px wide and drawn 320 px wide had 0 grey pixels across its black and white edge. A bitmap copy of the 20 px draw, scaled the same way, had 13. So the image is laid out once at 160 px and drawn at any width.
- Writing
sizesis enough to change the file. Fromsizes="20px"to"700px"the browser went from the 160w file to the 1280w file and raisedpaintwhen it loaded, with no load listener. The required width issizestimes the device pixel ratio: 91 px picked 160w at ratio 1 and 320w at 2.625. - The file doesn't go back down. After the 1280w file had loaded,
sizes="20px"leftcurrentSrcat 1280w, and so did a fresh copy of the<picture>element. Candidates with new URLs started from the small file again. - Writing
sizesduring a walk fetches every file on the way. 160w, 320w, 640w and 1280w were fetched for one walk from 91 to 1400 px. Withsizeswritten once at the end, only the first file and 1280w were fetched. - A turn and a squash are one affine matrix, and the hit region gets the same matrix. The middle of a bar landed at 200.6, 90.8 under the matrix,
elementFromPoint()returned the<rect>inside its link there, andgetBoundingClientRect()of the<rect>gave 200.6, 90.8. The label the canvas draws over a bar is placed from that box. :hoveron an SVG shape works under the transform and can be read in the paint handler. A mouse over the Thu bar turned its pixel to the hover colour (210, 73, 31), andquerySelector('a.bar:hover')in the handler returned it. A tap on a bar followed itshref:location.hashbecame#bar=tueand the page didn't scroll.- CSS animations and transitions inside the SVG raise
paint. 30 paint events in 0.5 s for an animatedstroke-dashoffset, 19 for a 0.3 s transition of a bar's transform, 0 for a still SVG. - A plain canvas inside a drawable figure is in the figure's picture, and redrawing it raises
painton the outer canvas. So does unticking a checkbox from script. The export demo has no change listener: the paint handler reads the checkboxes. - The inner canvas's content is drawn at the wrong place unless the canvas has
contain: paint. With 20 px of padding round it, a canvas with a red stripe at its left edge was drawn with the stripe missing and the blue part starting at 20 px, where 30 px was expected: the content is shifted by the padding and cut by the canvas's box. Withcontain: paintor a transform on the inner canvas it was drawn at the right place. A CSS background on the same canvas wasn't shifted. - One
toBlob()call on the outer canvas gave a PNG with the inner canvas and the HTML in it. The canvas wasn't tainted. At device pixel ratio 1 the demo's PNG was 378 by 288 px and 31 kB, andtoBlob()took 18 ms in the test browser. - A lost context shows every element as plain HTML. One dispatched
contextlostevent on one canvas stopped all five and left five boxes with the video, the figure, the picture, the chart and the legend in them. - Not verified: everything on a phone. In particular the speed of 12 to 40 video draws per frame, the native controls and the fullscreen button by touch, the on-screen keyboard over the caption, the file choice at the phone's pixel ratio (the line under the picture reports it), a touch drag on the chart, and Copy and Share for the PNG.