Pull-to-refresh and stretch overscroll
I wanted to see if one WebGL 2 canvas could hold a live scrolling mobile feed, stretch it from either edge like Android 12+, and pull a liquid metaball spinner out of its sticky header. Scroll inside the phone frame, tug past the top or bottom boundary, or press the trigger buttons to compare non-uniform UV strain against a uniform scale.
Starting...
Show the code drawable scroller markup, non-uniform stretch shader, metaball SDF and geometry sync
- Live scrollable feed inside one canvas. Making
#feed-scrollitself the singledrawableelement keeps sticky headers, inputs and scrolled cards in one paint record. - Non-uniform stretch fragment shader. Deforms texture Y near the pulled edge with
y - A * y * (1 - y) * exp(-k * y)and mirrors for bottom pulls. - Analytic 2D metaball pull-to-refresh droplet. Sums
r1/d1 + r2/d2from the header bottom edge and droplet sphere, snapping free past78 px. - Logarithmic rubber-band and damped spring physics. Shared between the main demo and the isolated live checks.
- Hit-box calibration with
updateElementGeometry(). Multiplies the transform bygeometryUnit()and flipsdataset.hitTick. - Five-argument 2D strip fallback. Copies a plain snapshot and draws slices with 5-argument
drawElementImage()when WebGL 2 isn't available.
How it works
The phone frame holds one <canvas content="drawable" layoutsubtree> managed by a single ElementGL WebGL 2 context from /lib/element-gl.js. Its only drawable child is #feed-scroll, which sets overflow-y: auto, overscroll-behavior-y: contain and touch-action: pan-y. Keeping drawable on the scroll container itself (and not on individual cards inside it) lets Chromium paint the sticky header, filter chips, text input and scrolled cards in one texture via gl.texElementSubImage2D() while native wheel and touch scrolling work directly on the box.
When you drag past scrollTop === 0 or past the bottom limit, excess delta passes through a logarithmic rubber-band curve 56 * log1p(d / 56) up to 120 px. In Android stretch mode, the fragment shader maps screen Y to texture Y using y - A * y * (1 - y) * exp(-3.2 * y). Because its slope is below 1 near y = 0 and slightly above 1 further down, rows near the pulled edge elongate up to 2.6x while distant rows compress gently and both boundaries stay fixed in the viewport. Uniform scale mode replaces that curve with linear scaleY() so you can compare the clipping and constant strain.
During a top pull above scrollTop === 0, the shader evaluates a two-source 2D metaball scalar field r1 / d1 + r2 / d2 anchored at the stretched bottom edge of the sticky header. Pulling towards 78 px thins the liquid neck until the critical distance breaks it cleanly into a floating sphere with a spinning loader arc, prepends a new timestamped row to the live DOM feed and springs pullPx back to 0. When the spring settles, or when the frame scrolls off screen, the animation loop stops completely.
WebGL uploads don't move hit regions by themselves, so syncGeometry() scales the feed's DOMMatrix by geometryUnit() from /lib/surface.js, passes it to canvas.updateElementGeometry() and toggles dataset.hitTick to clear Chromium's hit-test cache. If WebGL 2 isn't available, the canvas falls back to 5-argument drawElementImage() strips in 2D, and if the context is lost it moves #feed-scroll into plain HTML so controls stay usable.
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 Canary (2026-11-27, 412 px viewport at DPR 2.625): all four live checks pass, canvas memory stays at 10 MB (1.3 megapixels, peak 3 WebGL contexts during checks and 1 after retirement), and touch drag plus wheel scrolling keep the outer page stationary.
- Not verified on Chrome 159 for Android or through
npm run check:jankyet: real touch momentum handoff atscrollTop === 0, 2D strip fallback rendering and on-device WebGL frame timing need testing on a phone at 412 px. - Putting
drawableon the outer scroller (#feed-scroll) instead of on each card avoids Chromium's nested-drawable paint clipping and preserves native scrolling withoverscroll-behavior-y: contain. - Calling
stage.begin()beforestage.upload(feedEl)sizes the canvas backing store first sogetElementImageDefaultSize()reports full HiDPI pixels on the first paint instead of 300 by 150. - A
wheellistener attached to the<canvas>with{ passive: false }is cancelable when absorbing overscroll at the boundary, whereas a listener on a drawable scroll child is treated as passive by Chromium. - Mouse dragging downwards to pull-to-refresh inside the live DOM scroller also starts native text selection unless
#feed-scrolldisablesuser-select(while keepinguser-select: texton inputs) and cancelsselectstart. - Using
y - A * y * (1 - y) * exp(-k * y)keeps derivativedv/dy > 0everywhere forA <= 0.65, giving strong local elongation near the pulled edge with mild compression on distant rows and zero UV folding.