Live minimap of a page
A scrolling column of articles inside a canvas. Each <article> is drawn twice: at full size in the reading area, and at about a sixth of its size in the strip on the right.
The strip is drawn from the same live elements, so typing in the note, running the build or adding an article changes it at once.
Scroll the column by touch or wheel. Drag or tap in the strip to move the view. Overview flies every article out to a grid, and a tap on one flies back to it.
Show the code two draws per article, the rail, the overview
- The markup. A scroll container, articles with
drawableinside it, and an empty rail element for the strip. - On
paint. Draw every article small in the strip, then draw the ones in view at full size. The last draw of an element decides where its input goes. - Scrolling. The browser doesn't scroll a container that isn't drawable, so the page turns wheel and touch input into
scrollTop. - The rail. Pointer and key input on the strip sets
scrollTop. - Overview. A tap on an article in the grid scrolls to it.
- The paint loop,
put(),hitOnly()andpark(). - Styles.
How it works
Every article has drawable. The scroll container around them is laid out and scrolls, and has no picture. The picture of an article is the whole article, also when it's scrolled out of view. That's what lets the strip show the full page.
On each paint event the canvas draws the rail, then every article at the strip's scale, then a frame for the part in view. After that it draws the articles that are in view at full size, at offsetTop - scrollTop, clipped to the reading area.
An element's hit region is where it was drawn last, so articles in view take input in the reading area. An article out of view was last drawn in the strip. Its hit region is shrunk to a point with updateElementGeometry(), so the strip's input goes to the rail.
Scrolling has two routes, and the menu under the demo switches between them.
Route 1, the default: the scroll container isn't drawable. Chromium then doesn't scroll it for a wheel or a touch drag. The input goes to the page. The events still reach the container, because they bubble from the article that was hit.
The page sets scrollTop from the wheel delta and from touch movement, keeps moving after the finger lifts, and passes what is left over to the page when the container is at an end. Page Up and Page Down scroll it without help.
Route 2: the scroll container has drawable too and is drawn with no alpha, which gives it a hit region. The browser scrolls it. The cost is in the pictures. An article is now a drawable element inside a drawable element, and Chromium records only the part of it that is inside the container's box at that moment.
An article that changes while it's half out of view loses the hidden half in the strip, and the hole stays until the article changes again while fully in view. Switch to this route, scroll an article half out, press "New numbers" and look at the strip.
The rail is an empty element with touch-action: none, role="scrollbar" and a tab stop. Its hit region covers the strip. A drag on it sets scrollTop. Arrow keys, Page Up and Page Down work when it has focus.
The minimap covers the articles in this canvas only. An element can be drawn only into the canvas it is inside, so a minimap of the whole document would need the whole document inside one canvas.
Live checks
These run on their own small scroll containers in the corner of the window.
Findings
- In Chromium 157 a
drawablearticle inside a scroll container that isn't drawable keeps a whole picture wherever it is scrolled to, and when part of the canvas is outside the window. Changes to an article that is out of view show in the strip. - The browser doesn't scroll that container for a wheel or a touch drag on a drawn article. The page scrolls instead.
will-change, a transform,contain: paintandoverflow: scrollon the container made no difference. Keyboard scrolling andscrollTopwork. - A
wheellistener on that container is treated as passive: the event isn't cancelable and the page scrolls too. The same listener on the canvas can callpreventDefault().touch-action: noneon the container does stop the page panning. - With
drawableon the container as well, wheel and touch scroll it natively once it has a hit region. Its own picture leaves the articles out. - On that route an article's picture is cut to what was inside the container's box, and inside the window, when the article was last painted. The missing part is transparent,
drawElementImage()doesn't throw, and scrolling orrequestPaint()doesn't bring it back. A style change on the article while it's fully in view does. This is the reason the page defaults to route 1. - An article that was last drawn in the strip takes taps in the strip. The page parks it with
updateElementGeometry()at a scale of 0.001. touch-actionis per element:noneon the rail and on the scripted scroll container, the default on the native one.- Not verified: how the scripted touch scrolling feels on a phone next to native scrolling, and the on-screen keyboard over the note field.