Live view transitions

Shatter, fold, burn or morph between two states. A view transition animates screenshots. Here both states are DOM for the whole transition, so a clock keeps ticking on a flying shard, and you can stop half way and press a button on either side.

Welcome back

This card is a slotted <section>. Type here, then start a slow transition and keep typing.

State 1 of 3

Dashboard

0

A note

Buttons inside the cards also start a transition, from the point you clicked.

Show the code live transitions
  1. Each child of <live-transition> is one state. Ordinary HTML. data-morph names the parts that the morph effect pairs up.
  2. Switch states with show(), or begin() and set progress to hold part way. effect is the name picked in the row of buttons.
  3. Add your own effect: a GLSL function. Both states arrive as live textures.
  4. Inside the element: each state becomes a texture. This is the WebGL route; on WebGPU the call is device.queue.drawElementImageToTexture({ source }, { texture }). gl.texElementSubImage2D(…, element) copies the element's current rendering into a texture. It runs in the canvas paint event, and only for states the browser repainted.
  5. Inside the element: keep clicks landing on what you see. WebGL draws don't move an element's hit box, so canvas.updateElementGeometry(el, { canvasTransform }) tells the browser where the piece under the pointer was drawn.
  6. The whole element.
Write your own transition shader

Define vec4 transition(vec2 uv). You get getFromColor(uv), getToColor(uv), progress from 0 to 1, ratio (width ÷ height) and origin (where you clicked). It's the gl-transitions convention, so a shader written for that works here. Both states are live textures, so whatever you write is drawn from the DOM as it is this frame.

Use it

<script type="module" src="/lib/live-transition.js"></script>

<live-transition effect="shatter" duration="900">
  <section>…first state…</section>
  <section>…second state…</section>
</live-transition>

<script>
  const lt = document.querySelector('live-transition');
  await lt.show(1);                                   // play to the end
  await lt.begin(0, { effect: 'burn', origin: { x: 40, y: 40 } });
  lt.progress = 0.4;                                  // hold it there, both states interactive
  await lt.play();
</script>

Give elements in two states the same data-morph name and the morph effect flies one into the other. New mesh effects are one function: LiveTransition.effects.name = (progress, { W, H, quad, tri }) => …. Shader effects are a string: LiveTransition.shaders.name = { glsl: 'vec4 transition(vec2 uv) { … }' }. Without HTML-in-canvas the element shows one child at a time and falls back to document.startViewTransition.

Live checks

These run in your browser when this section is on screen, against the small rig below. They don't touch the demo above.

test rig
select me
popover

Findings