06Refraction follows cursor
Moving the pointer over a large glass panel drives --mx/--my custom properties that store the coordinates, so an elliptical specular highlight follows the cursor in real time like light sliding across glass.
Best forProduct hero panels, interactive banners
custom propertyradial-gradientJS 8줄

<main class="stage">
<div class="rh-panel rh-focal is-demo">
<span class="rh-panel__title">Hover the glass</span>
<span class="rh-panel__desc">Specular light follows the cursor</span>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// ── 변수 3개 ──────────────────────────────────────────
$duration: $dur-loop;
$easing: linear;
$color: $subject-cream;
// 커서 좌표 — 퍼센트로 등록해야 is-demo 의 키프레임이 값을 보간한다
@property --mx { syntax: '<percentage>'; inherits: true; initial-value: 50%; }
@property --my { syntax: '<percentage>'; inherits: true; initial-value: 50%; }
@include stage($stage-yellow);
.rh-panel {
position: relative;
overflow: hidden;
box-sizing: border-box;
width: min(300px, 86vw);
aspect-ratio: 300 / 190;
border-radius: $r-card;
background: rgba(255, 255, 255, .16);
border: 1px solid rgba(255, 255, 255, .4);
backdrop-filter: blur(14px) saturate(160%);
-webkit-backdrop-filter: blur(14px) saturate(160%);
box-shadow: $shadow-press;
display: flex;
flex-direction: column;
justify-content: flex-end;
gap: $sp-1;
padding: $sp-4;
color: $subject-ink;
font: 600 12px/1.3 -apple-system, "Segoe UI", sans-serif;
--mx: 50%;
--my: 35%;
}
.rh-panel__title { position: relative; z-index: 1; font-size: 13px; font-weight: 700; }
.rh-panel__desc { position: relative; z-index: 1; opacity: .75; font-weight: 500; }
// 실사용: 진짜 pointermove 가 --mx·--my 를 갱신한다(위 <script>)
.rh-panel::before {
content: "";
position: absolute;
inset: 0;
background: radial-gradient(120px 80px at var(--mx) var(--my), $color 0%, transparent 70%);
opacity: .7;
pointer-events: none;
}
// 데모 루프: is-demo 는 --mx·--my 를 keyframes 로 원을 그리며 돌려 캡처 (실 JS 와 별개 경로, 공존 가능)
@keyframes rh-drift {
0% { --mx: 15%; --my: 20%; }
25% { --mx: 85%; --my: 15%; }
50% { --mx: 85%; --my: 85%; }
75% { --mx: 15%; --my: 80%; }
100% { --mx: 15%; --my: 20%; }
}
.rh-panel.is-demo { animation: rh-drift $duration $easing infinite; }
@media (prefers-reduced-motion: reduce) {
.rh-panel.is-demo { animation: none !important; }
}@property --mx {
syntax: "<percentage>";
inherits: true;
initial-value: 50%;
}
@property --my {
syntax: "<percentage>";
inherits: true;
initial-value: 50%;
}
html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ffd23f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.rh-panel {
position: relative;
overflow: hidden;
box-sizing: border-box;
width: min(300px, 86vw);
aspect-ratio: 300/190;
border-radius: 16px;
background: rgba(255, 255, 255, 0.16);
border: 1px solid rgba(255, 255, 255, 0.4);
backdrop-filter: blur(14px) saturate(160%);
-webkit-backdrop-filter: blur(14px) saturate(160%);
box-shadow: 0 6px 12px rgba(23, 20, 26, 0.32);
display: flex;
flex-direction: column;
justify-content: flex-end;
gap: 4px;
padding: 16px;
color: #17141a;
font: 600 12px/1.3 -apple-system, "Segoe UI", sans-serif;
--mx: 50%;
--my: 35%;
}
.rh-panel__title {
position: relative;
z-index: 1;
font-size: 13px;
font-weight: 700;
}
.rh-panel__desc {
position: relative;
z-index: 1;
opacity: 0.75;
font-weight: 500;
}
.rh-panel::before {
content: "";
position: absolute;
inset: 0;
background: radial-gradient(120px 80px at var(--mx) var(--my), #fff7e6 0%, transparent 70%);
opacity: 0.7;
pointer-events: none;
}
@keyframes rh-drift {
0% {
--mx: 15%;
--my: 20%;
}
25% {
--mx: 85%;
--my: 15%;
}
50% {
--mx: 85%;
--my: 85%;
}
75% {
--mx: 15%;
--my: 80%;
}
100% {
--mx: 15%;
--my: 20%;
}
}
.rh-panel.is-demo {
animation: rh-drift 2s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
.rh-panel.is-demo {
animation: none !important;
}
}var panel = document.querySelector('.rh-panel');
panel.addEventListener('pointermove', function (e) {
var r = panel.getBoundingClientRect();
var x = ((e.clientX - r.left) / r.width * 100).toFixed(1) + '%';
var y = ((e.clientY - r.top) / r.height * 100).toFixed(1) + '%';
panel.style.setProperty('--mx', x);
panel.style.setProperty('--my', y);
});import { CSSProperties, PointerEvent, useCallback, useRef } from "react";
import styles from "./RefractionHover.module.scss";
type Vars = CSSProperties & {
"--color"?: string;
"--mx"?: string;
"--my"?: string;
};
export interface RefractionHoverProps {
color?: string;
}
// 실사용: 진짜 pointermove 가 --mx·--my 를 갱신한다. 하이라이트는 CSS 만으로 그 좌표를 그린다
export default function RefractionHover({ color = "#fff7e6" }: RefractionHoverProps) {
const panelRef = useRef<HTMLDivElement>(null);
const handleMove = useCallback((e: PointerEvent<HTMLDivElement>) => {
const el = panelRef.current;
if (!el) return;
const r = el.getBoundingClientRect();
const x = (((e.clientX - r.left) / r.width) * 100).toFixed(1) + "%";
const y = (((e.clientY - r.top) / r.height) * 100).toFixed(1) + "%";
el.style.setProperty("--mx", x);
el.style.setProperty("--my", y);
}, []);
const style: Vars = { "--color": color };
return (
<div className={styles.panel} style={style} ref={panelRef} onPointerMove={handleMove}>
<span className={styles.title}>Hover the glass</span>
<span className={styles.desc}>Specular light follows the cursor</span>
</div>
);
}06 Refraction follows cursor — Measured area 37.717% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · 9 CSS Glassmorphism Effects to Copy-Paste
The post this demo lives in
9 CSS Glassmorphism Effects to Copy-PasteCSS glassmorphism is the frosted-glass look: content on a panel that blurs whatever sits behind it, the way a shower doo See all demos in this post


