A canvas only while something moves

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 canvas

Step 1 of 2

Type a name, then go on.

In a canvas only for the transition

Step 1 of 2

Type a name, then go on.

AlwaysOnly 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
  1. The markup. The same card twice: once inside a canvas, once in a plain <div>.
  2. Styles.
  3. Drawing an element, and sweeping. One paint handler: draw the element, or run the transition from two copies.
  4. Wrap and unwrap. Make the canvas, move the element in with moveBefore(), and move it out again.
  5. 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