Liquid glass refraction
液态玻璃折射
Track a prismatic optical sheen across a frosted translucent glass panel.
Also searched as: 苹果液态玻璃, 毛玻璃跟随反光, 高光玻璃折射卡片, Liquid Glass
- Placement
- Card list, Button
- Mood
- Refined, Technical
- Trigger
- 悬停
- Site types
- 品牌官网, 工具和应用, 个人网站
How it works & accessibility
Applies backdrop-filter blur and saturation to a hairline-bordered surface while mapping pointer coordinates into CSS custom properties driving a radial specular highlight; touch holds light up locally and reduced motion skips fade transitions.
Best for: Card list, Button (悬停).
Reduced motion: 关闭高光淡入淡出过渡,保留清晰磨砂玻璃层与静置态光斑响应
Mobile & touch: 移动端触按时在指尖位置即时点亮折射光斑,松手后平稳收起,不阻挡滚动
Key parameters
| Parameter | Key | Default | Range | Notes |
|---|---|---|---|---|
| 折射光径 | size | 200px | — | — |
| 高光强度 | intensity | 68% | — | — |
| 磨砂模糊 | blur | 14px | — | — |
Ready-to-paste AI prompt
Add “Liquid glass refraction” to the card list in my project: Applies backdrop-filter blur and saturation to a hairline-bordered surface while mapping pointer coordinates into CSS custom properties driving a radial specular highlight; touch holds light up locally and reduced motion skips fade transitions.
Parameters: size: 200px, intensity: 68%, blur: 14px.
Preserve existing content and layout. Respect prefers-reduced-motion by showing the final state. Content must remain visible if JavaScript fails or is disabled.
Reference: https://donglang.linter.top/effects/liquid-glass.md (canonical specification and reference code).Dependency-free reference code
CSS
/* 注册成可插值的长度:演示里用 Web Animations 沿路径扫光,没注册的话浏览器只会在两个关键帧之间"跳"一下,看起来像抽帧 */
@property --lg-x { syntax: '<length-percentage>'; inherits: true; initial-value: 50%; }
@property --lg-y { syntax: '<length-percentage>'; inherits: true; initial-value: 50%; }
.lg-card {
position: relative;
overflow: hidden;
border-radius: 18px;
background: rgb(255 255 255 / 0.1);
border: 1px solid rgb(255 255 255 / 0.28);
box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.42), 0 18px 40px -20px rgb(0 0 0 / 0.65);
backdrop-filter: blur(var(--lg-blur, 14px)) saturate(1.6);
-webkit-backdrop-filter: blur(var(--lg-blur, 14px)) saturate(1.6);
}
.lg-sheen {
position: absolute;
inset: 0;
border-radius: inherit;
pointer-events: none;
opacity: 0;
mix-blend-mode: screen;
background-image: radial-gradient(
calc(var(--lg-size, 200px) / 2) calc(var(--lg-size, 200px) / 2) at var(--lg-x, 50%) var(--lg-y, 50%),
rgb(255 255 255 / 0.9),
rgb(187 230 232 / 0.42) 38%,
transparent 74%
);
transition: opacity 220ms cubic-bezier(0.16, 1, 0.3, 1);
}
.lg-card.is-lit .lg-sheen {
opacity: var(--lg-alpha, 0.68);
}
.lg-body {
position: relative;
z-index: 1;
}
@media (prefers-reduced-motion: reduce) {
.lg-sheen {
transition: none;
}
}JavaScript
// 液态玻璃折射(Liquid glass refraction)· 原生 JS,不依赖任何库。
// 用法:const ctl = liquidGlass(root, { size: 200, intensity: 68, blur: 14 });
// 支持 pointer 跟随与触屏按压点亮,返回值包含 show(x, y)、move(x, y)、hide()、destroy()。
export function liquidGlass(root, {
size = 200,
intensity = 68,
blur = 14,
ignoreReducedMotion = false,
} = {}) {
if (!root) return null;
const reduce = !ignoreReducedMotion && matchMedia('(prefers-reduced-motion: reduce)').matches;
const alpha = Math.max(0, Math.min(1, intensity / 100));
let sheen = root.querySelector('.lg-sheen');
const createdSheen = !sheen;
if (!sheen) {
sheen = document.createElement('span');
sheen.className = 'lg-sheen';
sheen.setAttribute('aria-hidden', 'true');
root.prepend(sheen);
}
const prevSize = root.style.getPropertyValue('--lg-size');
const prevAlpha = root.style.getPropertyValue('--lg-alpha');
const prevBlur = root.style.getPropertyValue('--lg-blur');
const prevTransition = sheen.style.transition;
root.classList.add('lg-card');
root.style.setProperty('--lg-size', `${size}px`);
root.style.setProperty('--lg-alpha', String(alpha));
root.style.setProperty('--lg-blur', `${blur}px`);
if (reduce) sheen.style.transition = 'none';
const move = (x, y) => {
root.style.setProperty('--lg-x', `${x}px`);
root.style.setProperty('--lg-y', `${y}px`);
};
const show = (x, y) => {
move(x, y);
root.classList.add('is-lit');
};
const hide = () => {
root.classList.remove('is-lit');
};
const local = (e) => {
const r = root.getBoundingClientRect();
const kx = r.width ? root.offsetWidth / r.width : 1;
const ky = r.height ? root.offsetHeight / r.height : 1;
return [(e.clientX - r.left) * kx - root.clientLeft, (e.clientY - r.top) * ky - root.clientTop];
};
const listeners = [
['pointerenter', (e) => { if (e.pointerType !== 'touch') show(...local(e)); }],
['pointermove', (e) => { if (e.pointerType !== 'touch' || root.classList.contains('is-lit')) move(...local(e)); }],
['pointerleave', (e) => { if (e.pointerType !== 'touch') hide(); }],
['pointerdown', (e) => { if (e.pointerType === 'touch') show(...local(e)); }],
['pointerup', (e) => { if (e.pointerType === 'touch') hide(); }],
['pointercancel', (e) => { if (e.pointerType === 'touch') hide(); }],
];
listeners.forEach(([type, fn]) => root.addEventListener(type, fn));
return {
show,
move,
hide,
destroy() {
listeners.forEach(([type, fn]) => root.removeEventListener(type, fn));
root.classList.remove('is-lit');
root.style.removeProperty('--lg-x');
root.style.removeProperty('--lg-y');
if (prevSize) root.style.setProperty('--lg-size', prevSize);
else root.style.removeProperty('--lg-size');
if (prevAlpha) root.style.setProperty('--lg-alpha', prevAlpha);
else root.style.removeProperty('--lg-alpha');
if (prevBlur) root.style.setProperty('--lg-blur', prevBlur);
else root.style.removeProperty('--lg-blur');
sheen.style.transition = prevTransition;
if (createdSheen) sheen.remove();
},
};
}HTML
<div class="lg-card" data-glass>
<span class="lg-sheen" aria-hidden="true"></span>
<div class="lg-body">
<small>OPTICAL SURFACE</small>
<b>液态玻璃层</b>
<p>指针经过时高光沿边缘漫射流转</p>
</div>
</div>