Press "Next" on each card. The transition is the same on both. The first card is always inside a canvas. The second is plain HTML until you press, then it's moved into a canvas that's made for the transition and removed when it ends. The table under them shows what each one cost.
After VFX-JS Transitions by AMAGI, which wraps an element in a canvas only while a transition plays.
Always in a canvasIn a canvas only for the transition
Step 1 of 2
Type a name, then go on.
Always
Only for the transition
Canvas memory while nothing moves
-
-
Canvas memory during the transition
-
-
Press to first frame of the transition
-
-
Paints a second, longest gap
-
-
Focus after the transition
-
-
Show the code the markup, the permanent canvas, the wrap and unwrap, the two presses
The markup. The same card twice: once inside a canvas, once in a plain <div>.
Styles.
Drawing an element, and sweeping. One paint handler: draw the element, or run the transition from two copies.
Wrap and unwrap. Make the canvas, move the element in with moveBefore(), and move it out again.
The two presses.
How it works
Both cards are the same <article> with a text field and a button. Pressing the button toggles a class that changes the card's colours and words. The transition between the two looks is the dome of light from the theme sweep page: a copy of the old look, a copy of the new look, and frames made from the two copies.
Always. The first card is a child of a canvas from the start. A paint handler draws it with drawElementImage() whenever the browser says it changed, which includes every blink of the caret in its text field.
Only for the transition. The second card sits in a <div>. When you press its button, the page makes a canvas the size of the card, puts it where the card is, and moves the card into it with moveBefore(). A new canvas is empty until its first paint event, so a lifeless copy of the card (a clone, made inert) sits behind the canvas until the first draw. Then the transition runs as on the first card. When it ends the card is moved back out, the canvas is removed, and its memory is given back.
The numbers. Memory is the page's own sum of width by height by 4 bytes for the canvases each card is using: its canvas, and the plain canvas that holds the two copies during a transition. "Press to first frame" runs from the click event to the first paint that draws a frame of the sweep. "Run each 5 times" gives the middle value of five, and sends the table to this site's report log.
Live checks
These run on their own cards in the corner of the window, not on the two above. Two of them move keyboard focus to a button on those cards, so they wait for a tap.
Findings
An element doesn't have to live in a canvas to get a canvas transition. The second card is plain HTML until its button is pressed, is drawn by a canvas for 0.9 seconds, and is plain HTML again afterwards.
moveBefore() is what makes it usable. The pressed button kept focus on the way into the new canvas and on the way out, and a field kept its typed text and its selection. The same move with insertBefore() left focus on <body>, which the failing live check above shows.
In Chromium 157 a canvas made in a click handler had drawn the moved card by the next animation frame, 13 ms after the call in a live check. Making the canvas and moving the card took 0.6 ms.
I couldn't measure a delay from making the canvas. Over five presses each at device scale 2.625, the middle time from the click to the first frame of the transition was 32.9 ms for the permanent canvas and 33.1 ms for the one made on the spot. Single presses ranged from 19 to 50 ms on both. The test browser renders in software, so a phone's numbers aren't known: "Run each 5 times" reports them.
At rest the permanent canvas holds 2.0 MB for a card of 412 by 175 CSS pixels at scale 2.625, and the other card holds none. During the transition both hold 6.0 MB, because the two copies need a plain canvas twice the size of the card. The site's guard stopped counting the removed canvas within 1.2 seconds.
The copy behind the new canvas is a precaution. With the box unticked the transition looked the same in the test browser, and I can't tell from a headless browser if a phone would show one empty frame.
The card made on the spot needs no fallback. In a browser without the API it stays where it is and changes with no transition. The card in the permanent canvas wasn't shown at all there, since a canvas doesn't show its children without the API, and the page has to take it out.
What the permanent canvas costs beyond memory is a repaint for every change to the card, including each blink of the caret, and the rules a drawn element lives under: no native scrolling inside it, and a hit box that follows the last draw. The second card has none of that while nothing moves.
What the canvas made on the spot costs is a parent that must be able to take a canvas in the card's place. The canvas is sized from the card once, so a card that changes size during the transition would be cut or stretched. I didn't try a card in a grid or flex row whose siblings depend on its type.
With reduced motion on, neither card makes a transition and the second never makes a canvas.