Liquid glass floating toolbar
I wanted to see if one WebGL 2 canvas could float a translucent iOS 26 style glass capsule dock over a live scrollable HTML feed, refracting and dispersing passing cards through a bevelled capsule edge while keeping buttons on both layers clickable. Scroll the feed, drag the glass dock over the photo cards, tap tabs, or compare Liquid refraction, Flat frosted glass and Magnify x1.4.
Starting...
Show the code two-child canvas markup, blur FBO, capsule SDF refraction shader and hit-test sync
- Two drawable subtrees in one canvas.
#lt-feedhandles native vertical scroll while#lt-dockfloats on top withtouch-action: none. - Separable offscreen blur FBO. Blurs
#lt-feedinto a half-resolution framebuffer, then unbinds both FBO and VAO before compositing to screen. - Analytic capsule SDF refraction shader. Computes the exact rounded-capsule gradient, traces Snell's law per RGB channel along the curved rim and composites crisp premultiplied
#lt-dockpixels on top. - Texture upload and geometry sync. Applies
UNPACK_PREMULTIPLY_ALPHA_WEBGL = true, callsstage.begin()beforestage.upload(), and updatesupdateElementGeometry()plusdataset.hitTickwhenever the dock moves. - Five-argument 2D and plain HTML fallbacks. Draws both children with 5-argument
drawElementImage()without WebGL 2, and moves both to plain HTML on context loss.
How it works
Both #lt-feed and #lt-dock sit as direct drawable children inside one <canvas content="drawable" layoutsubtree> managed by a single ElementGL WebGL 2 context. Keeping gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true) active at creation and on restore stops translucent white capsule borders and the sliding .lt-pill indicator from washing out to opaque white during gl.texElementSubImage2D() uploads.
Whenever the feed changes or scrolls, a separable four-pass blur pipeline blurs the feed texture into a half-resolution offscreen framebuffer, then unbinds the framebuffer and VAO before ElementGL draws to the screen. Inside the main fragment shader, pixels outside the floating capsule draw #lt-feed directly with a soft drop shadow. Pixels inside the capsule evaluate the exact analytic gradient of a rounded rectangle SDF, derive a 3D surface normal across a 20 px curved bevel, and trace refract() for red, green and blue at slightly offset refractive indices so passing stripes bend inward and split into fringes near the rim.
After mixing the refracted feed with the blurred offscreen underlay and adding a directional top-rim specular glint, the shader composites #lt-dock at 1:1 CSS layout coordinates so button labels and SVG icons stay sharp. Dragging the dock moves its hit box through updateElementGeometry() calibrated by geometryUnit() and flips dataset.hitTick to clear Chromium's hit-test cache, while an IntersectionObserver and document.hidden pause the spring loop off screen.
Live checks
Each check builds an isolated fixture on testStage() without scrolling or focusing the demo above. Press Run to execute them in this browser.
Findings
- Measured in headless Chrome 160.0.8188.0 Canary (2026-11-27, 412 px viewport at DPR 2.625): all six live checks pass; canvas memory stays at 10.3 MB (
948x1361, 1.29 MP, peak 12.9 MB during checks) with0lost contexts,0open snapshots,0unasked readbacks andscrollWidth === 412. - Not verified on Chrome 159 for Android or via
npm run check:jankyet: touch drag handoff across#lt-dockand#lt-feed, real GPU frame pacing and automated layout-shift tracking still need a phone run. - Unbinding the offscreen blur FBO (
gl.bindFramebuffer(gl.FRAMEBUFFER, null)) and VAO before callingstage.begin()and resettinggl.activeTexture(gl.TEXTURE0)keepsElementGL.upload()from clobbering the blur texture binding on the next paint. - Sampling
#lt-dockat 1:1 CSS pixels after computing bevel refraction and chromatic dispersion lets tab labels stay crisp even while the active pill indicator stretches horizontally during drags.