Liquid glass toolbar over scrolling DOM
I wanted to know if a floating HTML navigation pill can refract a live scrolling article behind it using Snell's-law lensing and chromatic dispersion in WebGL, while both the toolbar and the page underneath stay clickable and selectable. Scroll the article, drag the pill across the high-contrast cards, and try the buttons on both layers.
Show the code two-pass ElementGL liquid glass shader, scrolling upload and synced hit boxes
- Two drawable children in one canvas. The scrollable article fills the stage; the floating toolbar sits at the top-left in layout and moves via
updateElementGeometry(). - The fragment shader. Pass 0 draws the scrolling article. Pass 1 computes a rounded-rectangle SDF normal map, refracts the article texture with Snell's law and chromatic dispersion, applies a 9-tap frost blur and Fresnel specular rim, then composites the live toolbar on top.
- On
paint. Upload both elements into oneElementGLcontext, bind the article texture to unit 1 for the glass pass, and sync hit boxes withupdateElementGeometry(). - Dragging and presets. Move the pill by pointer or touch, keep clicks on toolbar buttons working, and toggle
dataset.hitTickwhen the hit box moves.
How it works
This experiment takes inspiration from Apple's Liquid Glass material design (WWDC 2025) and community WebGL and
WebGPU refractive glass UI demos. CSS backdrop-filter: blur() can frost pixels behind a floating bar,
but it can't bend them around a curved bevel or split red, green and blue like a physical lens. HTML-in-canvas gives
a fragment shader the live rendered pixels of the DOM behind the bar as a GPU texture, so the shader can run Snell's
law on every frame while the markup stays interactive.
Both #lg-page (the scrollable article) and #lg-dock (the floating navigation pill) live
inside one <canvas content="drawable" layoutsubtree> managed by ElementGL from
/lib/element-gl.js. Inside the paint handler, each element is uploaded with
gl.texElementSubImage2D() when it changes or when the article scrolls. Pass 0 draws the article across
the full canvas. Pass 1 draws a quad at the pill's current rectangle, binds the article texture to
TEXTURE1 and the pill's own DOM texture to TEXTURE0, evaluates a rounded-rectangle signed
distance field for the curved glass bevel, refracts three slightly different indices of refraction for red, green
and blue, adds a 9-tap frosted micro-blur and pointer-lit Fresnel highlight, and composites the crisp toolbar pixels
over the glass body.
Because the pill is drawn at its dragged coordinates rather than at its CSS layout origin, the paint handler calls
canvas.updateElementGeometry() for both children (scaled by geometryUnit() from
/lib/surface.js for high-DPI screens) and toggles dataset.hitTick whenever the pill moves
to clear Chromium's hit-test cache. When WebGL texElementSubImage2D() isn't available, the page falls
back to a 2D frosted draw with drawElementImage() or unwraps the markup as plain HTML with
backdrop-filter: blur().
Live checks
These run on their own small fixtures in the corner of the window and leave the demo above untouched.
Findings
- Apple's Liquid Glass material design (WWDC 2025) and community WebGL and WebGPU refractive glass UI demos inspired this layout. With CSS
backdrop-filter: blur()alone, a floating toolbar can blur what sits behind it, yet it can't curve the background along a bevel or separate RGB channels through a lens. - Putting both the scrolling container and the floating toolbar in one
ElementGLcanvas avoids opening a second WebGL context and lets the glass pass sample the scrolling article directly on texture unit 1. - Listening to
scrollon#lg-pageand callingrequestPaint()with a dirty flag makes sure the article texture re-uploads while you scroll, even if a browser build doesn't list a scroll-only update inchangedElements. - Keeping
#lg-dock's own CSS background transparent lets the fragment shader render the refracted lens, Fresnel rim and pointer glint behind the toolbar's live text and buttons, then composite the premultiplied DOM texture over the glass. - Setting
touch-action: noneon the floating pill andtouch-action: pan-yon the article lets you drag the pill on a touch screen without scrolling the outer page, while dragging outside the pill scrolls the article normally. - Not verified: live rendering, scroll smoothness, touch dragging and frame rate in Chromium 157 (headless) and Chrome 159 on Android. Open the page in a browser with HTML-in-canvas enabled and tap Run on the live checks above to verify on your device.