Scroll areas drawn over scroll containers, a range and details

Five more controls from ui-feed.dev, rebuilt with HTML-in-canvas. These ones are about what happens while something scrolls, resizes or opens: a paint chart whose chips stack up as they leave, a list whose rows turn over beside the thumb you hold, a bank statement with a heading that shrinks, a seismograph split by a bar you drag and the running order of a record. I wanted to know whether a real scroll container, with its wheel, touch and keys, could be drawn in pieces and bent out of shape by the canvas while it carries on scrolling natively.

Credit: every control on this page is a rebuild of a demo on ui-feed.dev, and each section links to the original it came from. The originals are far higher fidelity than these, so go and look at them. These are examples of what HTML-in-canvas makes possible with a native element underneath, not replacements. I worked from the published demos rather than their source: I looked at what each one does, worked out the mechanism and built it again. The designs and the ideas are theirs.

Paint chart

One <div> that scrolls, with a row for each colour. The canvas draws it twice: as it is from a little way down, and squashed into the top strip in ten bands, each flatter than the one under it, so the colours that have scrolled away pile up like chips seen edge on. The wheel, a swipe and the arrow keys all scroll the real container. The pill on the right is a thumb the canvas draws over an empty <div> that takes the drag.

After the paint chart (scroll area) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. One option for each colour; data-dark gives it light text.
  2. The control. The container drawn as it is and in squashed bands, and the thumb.
  3. The base class. The shadow root, the canvas, the paint loop and the plain HTML fallback.

Dragging the thumb

A scroll container of tracks and a thumb the canvas draws. While you hold the thumb, the rows level with it are drawn from a second copy of the list with every label on black, so the names you are passing stand out. The copy is inert and hidden from assistive technology, and it is drawn at the container's scroll position inside a band that opens on a spring when you press and closes when you let go.

After dragging the thumb (scroll area) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. One option for each track.
  2. The control. The list, the copy on black and the band beside the thumb.

Account statement

Each day is a <section> with a position: sticky heading, inside a scroll container. The big heading of the month is drawn smaller and fainter over the first 120 units of scroll, a one-line heading fades in in its place, and the container grows into the room it leaves. The balance after each payment is worked out from the closing balance on the element and written into an <output>.

After the account statement (scroll area) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. One option for each payment, newest first, with its day.
  2. The control. The balances, the sticky days and the heading that shrinks.

Seismograph

The bar between the trace and the table of events is an <input type="range">, so it has a value, a label and Page Up and Down. A range is dragged along its length, so the control turns a drag across it into a value and swaps Up and Down so the bar moves the way the key points. The table is a scroll container that gets the height the trace leaves. The canvas draws the trace, a row a minute with the newest at the bottom, the glow and the scan lines.

After the seismograph event list (resizable) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. One option for each event: the time, the magnitude, the depth and the place.
  2. The control. The range as a bar, the keys, the trace and the table.

LP running order

A <details> for each side of the record, with a row for each track. Closed, a side is one hatched bar on the time axis. As it opens, the bar of each track drops out of it to its own row, one after another, and the side below moves down with the drawn height rather than jumping with the layout.

After the LP running order (waterfall) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. An optgroup for each side and an option for each track.
  2. The control. The sides, the axis and the bars that drop.
  3. A <details> that closes over time.

How it works

Each control is a custom element on the same base class as the list controls. Its shadow root holds a canvas with content="drawable", and the native elements are children of that canvas.

Three of the controls are built round a scroll container. The canvas draws its picture where and how it likes, and the container still scrolls itself: the wheel, a swipe and the keys move scrollTop, the element raises a paint event, and the canvas draws it again. Where the drawing bends the container (the squashed chips), a last draw with no alpha at its real size puts the hit region back, so a swipe anywhere on it still scrolls.

A scroll bar inside a canvas isn't drawn, so each one here is drawn by the canvas over an empty <div> that takes the drag and sets scrollTop. The split in the seismograph is a range input rather than a <div>, so it has a value and keys of its own.

Live checks

Findings