Accordion from <details> that unfolds

Four <details> elements with the same name, drawn by a canvas. Tap a heading. The browser opens that one and closes the other in the same instant. The canvas has a picture of the closed one from before it closed and a live picture of the one that opened, and joins them with a fold: the content is cut into strips that open like folded paper. The controls inside the open section work, also while it unfolds.

Storage

6.2 GB of 10 GB used. Photos take the most space.

Notifications
Appearance

Accent colour

Account

Signed in on 3 devices. What was measured

 

Show the code the two pictures, the strips
  1. The markup. Ordinary <details name> elements, each with drawable.
  2. Notice a change and keep the open picture. Each paint compares open with the last paint. While a section is open and at rest, the canvas keeps a snapshot of it.
  3. Draw the content as strips. One clipped, sheared and squashed draw for each strip, then a shade over it.
  4. On paint. Stack the sections at their animated heights.
  5. Styles, including the CSS route.

How it works

A closed <details> has no box for its content, so its picture is only the summary. The open picture exists only while it's open. An animation between the two needs both at once, and the browser changes the state in one step.

Closing. On every paint while a section is open and not animating, the canvas calls captureElementImage() and keeps the result. When a later paint finds the section closed, the content strips are drawn from that snapshot, folding shut. This also covers a section that the browser closed because another one with the same name was opened: the page gets no warning before that happens.

Opening. The section is already open in layout, so the strips are drawn from the live element. Each strip is a clipped drawElementImage() with a transform that squashes it vertically and shears it sideways, alternating direction, and a dark or light fill over it. A last draw with no alpha puts the hit region of the whole section at its final size, so its controls can be used during the fold.

Positions. The layout jumps at once. The canvas ignores the layout positions and stacks the sections itself, using an animated height for each.

CSS route. With "CSS height transition" the page does none of that. interpolate-size: allow-keywords and a transition on ::details-content make the browser animate the height, each frame raises a paint event, and the canvas draws every section where layout puts it.

Live checks

These run on their own <details> elements in the corner of the window.

Findings