Experiment 01 材质研究
液态玻璃 Dock
把这块玻璃往左右拖。它会跟着手拉伸,下面的刻度朝反方向滑动,两端泛起色散,松手后回到原位。九行物理,零关键帧。
实时实验 · 01
左右拖动后松手。右上角开关可以在完整效果与随附的降级版本之间切换。
01
你能感到什么
把效果拆成几个部分,每一部分都对应一个可以改的数字。
- 拉伸
- 玻璃保持体积守恒。往右拉时尾端滞后、整体变宽,前端的圆角被拉得更紧。形变完全由速度决定,没有任何关键帧。
- 折射
- 玻璃下面不是模糊壁纸,而是整页的放大副本,以手指为中心缩放。边缘的内容比玻璃本身走得更多,所以刻度看起来在向后游。
- 回弹
- 松手后位置积分一条阻尼弹簧:k 170,c 16,ζ 0.61。先过冲约 8%,再稳定下来。形变比位移衰减得更快,所以玻璃会先变直、再停下。
02
Prompt 本体
写来复现行为本身,而不只是外观。可以直接粘进 Claude Code、Cursor 或 v0。
You are a front-end engineer with an eye for materials. Build a single HTML page that demonstrates exactly one idea: a glass dock that deforms under a drag. Every number below exists to make that read as a physical slab, not a decorated rectangle.
[The scene]
- Full-viewport stage, no scroll. Background: a soft three-stop gradient (light: #F6F2EA → #EAE7F4 → #E6F1EC; dark: #08080C → #0C0D16 → #070F11) with three large radial blooms (peach, violet, mint in light; stronger, more saturated in dark). No blur filters on the blooms — radial gradients are already soft, and blurring them costs a full-screen pass twice.
- Structure over the whole scene: 1px vertical rules every 88px plus 1px diagonal rules every 34px at 105° and about 14% ink. Mask both with a soft radial so the centre stays crisp.
- Top-left: a mono kicker, a two-line headline at clamp(30px, 5.2vw, 62px) with -0.045em tracking, and one paragraph at 13px/1.7 in a muted ink.
- Two small spec cards sit above the lower third, plainly bordered, no glass on them.
- Across the dock's travel band, a measuring strip: one hairline, tick marks every 14px (11px tall) with a 70px major tick (24px tall), a row of labels, and large numerals 0–6 at 118px and 11% opacity. This strip is the point: without structure under the glass, refraction is invisible.
[The slab]
- Seven 52px icons, 14px radius, 10px gap, 19px 20px padding, 26px slab radius, sitting in a flex row centred in the lower third.
- Icons are soft-tinted gradient tiles (one hue each, roughly 52% saturation) with a 1px inner top highlight; all glyphs are inline SVG in currentColor.
- Inside the slab, bottom to top: a lens layer that clips a magnified copy of the scene; a tone layer of white 9% → 1% → 5% top to bottom; a dispersion layer with a red gradient at the left end and a cyan gradient at the right, at screen blend, whose opacity is 0 until the slab is deformed; a specular sweep, a 104° white gradient band whose x-offset is driven by velocity; a 1px inner rim that is brightest along the top edge; and an outer shadow of 0 30px 70px -24px at 55% of a violet-black in light, 90% pure black in dark.
[The refraction, exactly]
- Clone the scene subtree once at load, drop its data attributes, mark it aria-hidden, and place it inside the slab at position absolute, left 0, top 0, 100vw × 100vh. Its coordinates are now viewport coordinates.
- Let s = (sx, sy) be the slab's current scale, O the slab's transform-origin (the leading edge, vertically centred), B the slab's untransformed viewport position, P the pointer in viewport coordinates, and x the slab's horizontal translation. Each frame compute
T = O + ((P - B) - O - (x, 0)) / s - P
and set on the clone: transform-origin P; transform: translate(T) scale(k/sx, k/sy).
- k = 1.09 + 0.08 × falloff, where falloff eases to 1 while the pointer is on the slab. Applying the inverse of the slab's own scale inside T is what keeps the copy exactly registered with the scene, so the content under the glass is displaced only by the magnification and not by a fudge factor.
- Mask the lens with one static radial gradient: fully opaque to 58%, 82% at 84%, 34% at 96%, transparent at the edge. The ends of the slab therefore fade instead of cutting hard. Never animate a mask per frame.
[The physics]
- Integrate one spring for the horizontal position. While dragging: stiffness 480, damping 38, target = dock start + pointer delta, clamped with a tanh rubber band that allows about 80px of give past the travel limit. On release: stiffness 170, damping 16 (ζ ≈ 0.61, about 8% overshoot) back to zero.
- Deformation e = min(1, |v| / 1100), eased by 0.16 per frame. scaleX = 1 + 0.2e, scaleY = 1 − 0.085e, with the transform-origin on the leading edge so the trailing end stretches and the leading corners tighten.
- Icon magnification: scale 1 + 0.42·exp(−d²/116²), lifting up to 9px, measured from the pointer to each icon's centre.
- Run one requestAnimationFrame loop and stop it entirely once the slab is at rest, the pointer has left and the deformation has decayed. A dock that keeps a rAF loop alive while idle is a battery bug.
[Fallback]
- prefers-reduced-motion, or navigator.hardwareConcurrency ≤ 2, or deviceMemory ≤ 2: start in fallback. No lens, no stretch, position follows the pointer directly with a stiff spring.
- Self-calibrating guard: record the frame rate measured in the first second of interaction on this machine; if a later drag averages under 60% of that baseline for three consecutive one-second samples, switch to fallback. Never use an absolute fps threshold — a throttled tab or a software compositor would be misjudged.
- Expose the same switch as a visible toggle so the fallback can be inspected instead of taken on trust.
- Keep the fallback a real design: tinted slab, rim, icons, still draggable.
[Interaction and access]
- Pointer Events with setPointerCapture, touch-action: none, and a grab/grabbing cursor.
- The dock is role="toolbar"; arrow keys move focus between icons and focus drives the lens, so keyboard users see the material too.
- Every icon has an accessible name. The demo renders no text the user must read to operate it.
- Output one complete HTML5 file. No libraries, no web fonts, no canvas, no WebGL, no SVG filters. Write noindex, nofollow in head and load no analytics.Light canvas: #F6F2EA → #EAE7F4 → #E6F1EC Dark canvas: #08080C → #0C0D16 → #070F11 Blooms: peach rgba(255,145,106,.72) · violet rgba(146,118,255,.58) · mint rgba(72,214,186,.52) Hairlines: ink at 12%; diagonal field ink at 14%, 34px pitch Glass tone: rgba(255,255,255,.09) → .01 → .05 Rim: rgba(255,255,255,.92) light · rgba(255,255,255,.50) dark Shadow: 0 30px 70px -24px rgba(28,24,44,.55) light · rgba(0,0,0,.90) dark Radii: slab 26px · icons 14px · cards 16px Icons: 52px, gap 10px, slab padding 19px 20px Type: system stack for prose; mono for all instrumentation, 9.5–11px, .16em tracking Headline: clamp(30px,5.2vw,62px) / 0.98 / -0.045em Motion: drag k480 c38 · release k170 c16 (ζ .61) · deform scaleX 1+.2e, scaleY 1−.085e Lens: k 1.09 + .08·falloff, masked to 58% opaque centre
- One HTML file plus compiled Tailwind; roughly 400 lines of CSS and 260 of JavaScript - Pointer Events with setPointerCapture; no gesture library - A single requestAnimationFrame loop that stops when the slab rests - One cloned subtree as the refraction source — no WebGL, no SVG filter, no canvas - Static masks and static gradients; nothing that forces a per-frame filter pass - Theme arrives through a THEME_CHANGE postMessage, so the study runs embedded and standalone
03
我们给自己定的规则
- 01 只做一个手势:水平拖动。没有上抛、没有旋转、没有缩放。
- 02 只有一个颜色来源:玻璃下方的场景。玻璃本身保持中性。
- 03 拖动过程不用关键帧、不用 transition——每一帧都由位置、速度和指针推导。
- 04 图标不离开玻璃体:放大倍率有上限,拉伸到极限时图标仍在玻璃内。
- 05 没有自主动画。静止时完全静止,玻璃稳定后动画循环直接停止。
- 06 关闭动效时布局完全一致。减少动态只移除物理,不改变设计。
04
性能降级
效果是有意会退化的。只能在快电脑上成立的材质叫 Demo,不叫设计。
- 减少动态:玻璃 1:1 跟手,不拉伸、不折射;场景只渲染一次,不再更新。
- 低端设备(2 核及以下、2GB 内存及以下)直接以降级模式启动,而不是拖到一半才发现卡。
- 帧率守卫是自校准的:先记录这台机器第一秒交互的帧率,之后只有在连续三秒低于自身基线的 60% 时才降级。用绝对阈值会把后台标签页和软件合成误判成慢设备。
- 降级是一个设计过的状态,不是坏掉的状态:仍有染色玻璃、描边、图标,仍然可拖拽——右上角开关就能看到它。
prefers-reduced-motion → 降级 · hardwareConcurrency ≤ 2 → 降级 · 拖动帧率连续 3 秒低于基线 60% → 降级
05
它不是什么
- 不是一个组件库。这一版没有 npm 包、没有 props、没有框架移植。
- 不是苹果的渲染实现。它逼近的是「玻璃为什么像玻璃」这件事,而不是 iOS 26 材质的内部算法。
- 没有在真实的低端 Android 设备上测过;降级逻辑靠模拟和自校准守卫验证,不是靠设备实验室。