06보내는 중 광택 띠가 지나가고 포인터 기울기를 따라 반사광이 옮겨 가는 버튼
보내는 동안 광택 띠를 대각선으로 반복해 지나가게 하고, 포인터 위치를 관성 lerp 로 천천히 따라가는 기울기 값에서 하이라이트 중심을 다시 계산한다.
쓰임결제하기·프리미엄 신청 버튼
SWEEP_MSGLOSS_WIDTHTILT_LERP

<main class="stage">
<div class="sb is-demo" id="sb">
<div class="sb__scene" data-role="scene">
<span class="gl__glow" data-role="glow" aria-hidden="true"></span>
<span class="gl__shadow" data-role="shadow" aria-hidden="true"></span>
<button class="gl__send" data-role="send" type="button">
<span class="gl__spot" data-role="spot" aria-hidden="true"></span>
<span class="gl__gloss" data-role="gloss" aria-hidden="true"></span>
<span class="gl__label" data-role="label">결제하기</span>
</button>
<p class="sb__status" data-role="status" aria-live="off">결제할 준비 됨</p>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
@include stage($stage-paper);
.sb {
position: relative;
width: min(92vw, calc(160vh - 12.8vw));
aspect-ratio: 480 / 300;
margin: 0 auto;
border-radius: $r-card;
overflow: hidden;
box-shadow: $shadow-raised;
}
// 장면 판 — 480×300 좌표로 짜 두고 스크립트가 상자 폭에 맞춰 scale 한다.
// 기준점이 왼쪽 위 모서리인 이유: 판이 상자 왼쪽 위에 붙어 있어 모서리 기준으로 줄여야 줄인 판이 상자와 겹친다
.sb__scene {
position: absolute;
left: 0;
top: 0;
width: 480px;
height: 300px;
transform-origin: 0 0;
}
.sb__canvas {
position: absolute;
left: 0;
top: 0;
width: 480px;
height: 300px;
pointer-events: none;
}
.sb__status {
position: absolute;
left: $sp-4;
bottom: $sp-3;
box-sizing: border-box;
max-width: 260px;
margin: 0;
padding: $sp-1 $sp-3;
border-radius: $r-pill;
background: rgba(255, 255, 255, .9);
color: $subject-ink;
font-weight: 500;
font-size: 12px;
line-height: 1.4;
pointer-events: none;
}
.sb__status--top {
top: $sp-3;
bottom: auto;
}
.sb__status--side {
max-width: 140px;
border-radius: $r-control;
}
.sb { background: #221d30; }
// 바닥 반사 — 진하기·위치는 스크립트가 광택 띠 진행률과 기울기에서 정한다
.gl__glow {
position: absolute;
left: 100px;
top: 150px;
width: 280px;
height: 96px;
border-radius: 50%;
background: radial-gradient(ellipse at center, rgba(255, 200, 216, .55), rgba(255, 200, 216, 0) 70%);
opacity: .2;
}
.gl__shadow {
position: absolute;
left: 140px;
top: 116px;
width: 200px;
height: 52px;
border-radius: $r-pill;
background: rgba(0, 0, 0, .5);
filter: blur(12px);
}
// 버튼 자리 = 스크립트의 BTN_CX 240 · BTN_CY 140 · 232×64
.gl__send {
position: absolute;
left: 124px;
top: 108px;
width: 232px;
height: 64px;
margin: 0;
padding: 0;
border: 0;
border-radius: $r-pill;
overflow: hidden;
background: linear-gradient(135deg, #ffd9c7, #ffc4d8);
color: $subject-ink;
font: inherit;
font-weight: 700;
font-size: 18px;
line-height: 1;
cursor: pointer;
}
.gl__send:focus-visible {
outline: 3px solid #ffffff;
outline-offset: 4px;
}
// 반사광 — 위치는 스크립트가 기울기에서 계산한 translate 로만 옮긴다
.gl__spot {
position: absolute;
left: 0;
top: 0;
width: 140px;
height: 140px;
border-radius: 50%;
background: radial-gradient(circle, rgba(255, 255, 255, .8), rgba(255, 255, 255, 0) 62%);
pointer-events: none;
}
.gl__gloss {
position: absolute;
left: 0;
top: -12px;
width: 46px;
height: 88px;
background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, .75), rgba(255, 255, 255, 0));
pointer-events: none;
}
.gl__label {
position: relative;
pointer-events: none;
}
@media (max-width: 340px) {
// 이 폭에서는 장면이 0.6 배 남짓으로 줄어든다 — 상태 줄 글자를 키워 줄인 뒤에도 읽히게 한다
.sb__status { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
// 움직임은 전부 스크립트가 그리고, 스크립트는 reduce 에서 루프를 돌리지 않고 결과 상태만 둔다. CSS 쪽 전환도 막아 둔다
.sb__scene * {
transition: none !important;
animation: none !important;
}
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ffffff;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.sb {
position: relative;
width: min(92vw, 160vh - 12.8vw);
aspect-ratio: 480/300;
margin: 0 auto;
border-radius: 16px;
overflow: hidden;
box-shadow: 0 14px 24px rgba(23, 20, 26, 0.32);
}
.sb__scene {
position: absolute;
left: 0;
top: 0;
width: 480px;
height: 300px;
transform-origin: 0 0;
}
.sb__canvas {
position: absolute;
left: 0;
top: 0;
width: 480px;
height: 300px;
pointer-events: none;
}
.sb__status {
position: absolute;
left: 16px;
bottom: 12px;
box-sizing: border-box;
max-width: 260px;
margin: 0;
padding: 4px 12px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.9);
color: #17141a;
font-weight: 500;
font-size: 12px;
line-height: 1.4;
pointer-events: none;
}
.sb__status--top {
top: 12px;
bottom: auto;
}
.sb__status--side {
max-width: 140px;
border-radius: 12px;
}
.sb {
background: #221d30;
}
.gl__glow {
position: absolute;
left: 100px;
top: 150px;
width: 280px;
height: 96px;
border-radius: 50%;
background: radial-gradient(ellipse at center, rgba(255, 200, 216, 0.55), rgba(255, 200, 216, 0) 70%);
opacity: 0.2;
}
.gl__shadow {
position: absolute;
left: 140px;
top: 116px;
width: 200px;
height: 52px;
border-radius: 999px;
background: rgba(0, 0, 0, 0.5);
filter: blur(12px);
}
.gl__send {
position: absolute;
left: 124px;
top: 108px;
width: 232px;
height: 64px;
margin: 0;
padding: 0;
border: 0;
border-radius: 999px;
overflow: hidden;
background: linear-gradient(135deg, #ffd9c7, #ffc4d8);
color: #17141a;
font: inherit;
font-weight: 700;
font-size: 18px;
line-height: 1;
cursor: pointer;
}
.gl__send:focus-visible {
outline: 3px solid #ffffff;
outline-offset: 4px;
}
.gl__spot {
position: absolute;
left: 0;
top: 0;
width: 140px;
height: 140px;
border-radius: 50%;
background: radial-gradient(circle, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0) 62%);
pointer-events: none;
}
.gl__gloss {
position: absolute;
left: 0;
top: -12px;
width: 46px;
height: 88px;
background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0));
pointer-events: none;
}
.gl__label {
position: relative;
pointer-events: none;
}
@media (max-width: 340px) {
.sb__status {
font-size: 16px;
}
}
@media (prefers-reduced-motion: reduce) {
.sb__scene * {
transition: none !important;
animation: none !important;
}
}(function () {
const root = document.getElementById("sb");
if (!root) return;
const W = 480;
const H = 300;
const FIXED_DT = 16;
// 파스텔 팔레트 — 캔버스와 스크립트가 칠하는 색은 여기서만 고른다 (scss 쪽 색은 demo-tokens)
const INK = [38, 33, 52];
const PAPER = [255, 252, 246];
const CREAM = [255, 243, 224];
const SKY = [158, 208, 255];
const LILAC = [200, 184, 255];
const MINT = [156, 228, 204];
const PINK = [255, 182, 204];
const PEACH = [255, 214, 184];
function clamp(v, lo, hi) { return v < lo ? lo : (v > hi ? hi : v); }
function lerp(a, b, t) { return a + (b - a) * t; }
function easeOut(x) { const c = clamp(x, 0, 1); return 1 - Math.pow(1 - c, 3); }
function easeInOut(x) {
const c = clamp(x, 0, 1);
return c < 0.5 ? 4 * c * c * c : 1 - Math.pow(-2 * c + 2, 3) / 2;
}
function rgba(c, a) {
return 'rgba(' + Math.round(c[0]) + ',' + Math.round(c[1]) + ',' + Math.round(c[2]) + ',' + clamp(a, 0, 1).toFixed(3) + ')';
}
function mix(a, b, t) { return [lerp(a[0], b[0], t), lerp(a[1], b[1], t), lerp(a[2], b[2], t)]; }
// 시드 고정 난수 — 같은 시드면 같은 값이 다시 나온다 (32비트 정수 섞기)
function makeRng(seed) {
let s = seed >>> 0;
return function () {
s = (s + 0x6d2b79f5) >>> 0;
let t = s;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const sceneEl = root.querySelector('[data-role="scene"]');
const statusEl = root.querySelector('[data-role="status"]');
if (!sceneEl || !statusEl) {
return;
}
const scene = sceneEl;
const status = statusEl;
const reduceQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
const still = reduceQuery.matches;
const resizeHooks = [];
// 자동 시연 중인가 — 사람이 처음 만지는 순간 시연을 멈추고 처음 상태로 돌린 뒤 상태 줄을 읽어 주기 시작한다
let demo = root.classList.contains('is-demo');
function wake() {
if (!demo) {
return;
}
demo = false;
root.classList.remove('is-demo');
status.setAttribute('aria-live', 'polite');
resetIdle();
}
function say(text) {
if (status.textContent !== text) {
status.textContent = text;
}
}
// 장면 배율 — 480×300 좌표로 짠 판을 상자 폭에 맞춰 통째로 줄인다
let k = 1;
function fitScene() {
const w = root.clientWidth;
k = w > 0 ? w / W : 1;
scene.style.transform = 'scale(' + k.toFixed(4) + ')';
}
// 화면 좌표(CSS px) → 장면 좌표(480×300). 줄인 배율 k 로 나눠야 판 안의 위치가 된다
function toScene(clientX, clientY) {
const r = root.getBoundingClientRect();
return [(clientX - r.left) / k, (clientY - r.top) / k];
}
// 캡처 단계에서 듣는다 — 버튼 자신의 pointerdown 보다 먼저 시연을 끝내야 사람의 첫 누름이 처음 상태에서 시작한다
root.addEventListener('pointerdown', wake, true);
root.addEventListener('keydown', wake, true);
// 버튼 자리(장면 px) — scss 의 .gl__send 위치·크기와 같은 값
const BTN_CX = 240;
const BTN_CY = 140;
const BTN_W = 232;
const BTN_H = 64;
// 광택 띠가 버튼을 한 번 가로지르는 시간
const SWEEP_MS = 820;
// 광택 띠 너비(px) — 대각으로 기울여(skewX −22°) 지나간다
const GLOSS_WIDTH = 46;
// 기울기가 포인터 쪽으로 다가가는 비율 — 16ms 한 걸음마다 남은 거리의 12% 만큼 간다(관성 lerp)
const TILT_LERP = 0.12;
const TILT_MAX_DEG = 14;
const SPOT = 140;
const SEND_MS = 1700;
const DEMO_CYCLE = 3000;
const TXT_IDLE = '결제하기';
const TXT_SENDING = '보내는 중';
const TXT_SENT = '결제 완료';
const TXT_READY = '결제할 준비 됨';
const TXT_SEND = '결제 요청을 보내는 중';
const TXT_DONE = '결제 완료 — 영수증을 메일로 보냈어요';
const sendEl = root.querySelector('[data-role="send"]');
const labelEl = root.querySelector('[data-role="label"]');
const glossEl = root.querySelector('[data-role="gloss"]');
const spotEl = root.querySelector('[data-role="spot"]');
const shadowEl = root.querySelector('[data-role="shadow"]');
const glowEl = root.querySelector('[data-role="glow"]');
if (!sendEl || !labelEl || !glossEl || !spotEl || !shadowEl || !glowEl) {
return;
}
const glow = glowEl;
const send = sendEl;
const label = labelEl;
const gloss = glossEl;
const spot = spotEl;
const shadow = shadowEl;
let phase = 'idle';
let pt = 0;
let tx = 0;
let ty = 0;
let gx = 0;
let gy = 0;
let demoNext = 200;
// 관성 lerp 한 걸음 — 목표로 곧장 가지 않고 남은 거리의 TILT_LERP 만큼만 간다
function follow(cur, goal) { return cur + (goal - cur) * TILT_LERP; }
// 광택 띠의 x — 한 번 지나가는 동안 왼쪽 밖(−2×너비)에서 오른쪽 밖(버튼 너비 + 너비)까지
function glossX(t) {
const p = (t % SWEEP_MS) / SWEEP_MS;
return lerp(-GLOSS_WIDTH * 2, BTN_W + GLOSS_WIDTH, easeInOut(p));
}
// 하이라이트 중심 — 포인터가 아니라 지금의 기울기(tx, ty)에서 다시 계산한다. 그래서 반사광도 늦게 따라온다
function spotCenter() { return [BTN_W / 2 + tx * BTN_W * 0.38, BTN_H / 2 + ty * BTN_H * 0.5]; }
function resetIdle() {
phase = 'idle';
pt = 0;
label.textContent = TXT_IDLE;
say(TXT_READY);
}
function finish() {
phase = 'done';
pt = 0;
label.textContent = TXT_SENT;
say(TXT_DONE);
}
function settle() { finish(); }
function press() {
if (phase === 'sending') {
return;
}
if (still) {
finish();
return;
}
phase = 'sending';
pt = 0;
label.textContent = TXT_SENDING;
say(TXT_SEND);
}
function aim(clientX, clientY) {
const p = toScene(clientX, clientY);
gx = clamp((p[0] - BTN_CX) / (BTN_W / 2 + 40), -1, 1);
gy = clamp((p[1] - BTN_CY) / (BTN_H / 2 + 60), -1, 1);
}
function step() {
if (still) {
tx = gx;
ty = gy;
return;
}
tx = follow(tx, gx);
ty = follow(ty, gy);
if (phase !== 'sending') {
return;
}
pt += FIXED_DT;
if (pt >= SEND_MS) {
finish();
}
}
function demoTick(t) {
// 시연 포인터 — 버튼 둘레를 리사주 곡선으로 돈다
gx = 0.85 * Math.cos(t * 0.0021);
gy = 0.7 * Math.sin(t * 0.0033);
if (t < demoNext) {
return;
}
demoNext += DEMO_CYCLE;
resetIdle();
press();
}
function draw() {
send.style.transform = 'perspective(520px) rotateX(' + (-ty * TILT_MAX_DEG).toFixed(2) + 'deg) rotateY(' + (tx * TILT_MAX_DEG).toFixed(2) + 'deg)';
const c = spotCenter();
spot.style.transform = 'translate(' + (c[0] - SPOT / 2).toFixed(1) + 'px,' + (c[1] - SPOT / 2).toFixed(1) + 'px)';
spot.style.opacity = (0.45 + 0.4 * Math.min(1, Math.hypot(tx, ty))).toFixed(3);
// 그림자는 기울기 반대쪽으로 크게(가로 22px·세로 14px) 밀린다 — 같은 tx·ty 가 버튼 밖 넓은 바닥까지 전파된다
shadow.style.transform = 'translate(' + (-tx * 22).toFixed(1) + 'px,' + (14 - ty * 14).toFixed(1) + 'px) scale(' + (1 - Math.hypot(tx, ty) * 0.05).toFixed(3) + ')';
// 바닥 반사 — 광택 띠가 버튼 가운데를 지날 때 가장 밝다(띠 진행률의 사인). 위치는 기울기 쪽으로
let band = 0;
if (phase === 'sending') {
band = Math.sin(Math.PI * ((pt % SWEEP_MS) / SWEEP_MS));
}
glow.style.transform = 'translate(' + (tx * 24).toFixed(1) + 'px,' + (ty * 10).toFixed(1) + 'px)';
glow.style.opacity = (0.2 + 0.6 * band).toFixed(3);
if (phase === 'sending') {
gloss.style.opacity = '';
gloss.style.transform = 'translateX(' + glossX(pt).toFixed(1) + 'px) skewX(-22deg)';
}
else {
gloss.style.opacity = '0';
}
}
gloss.style.width = GLOSS_WIDTH + 'px';
root.addEventListener('pointermove', function (ev) { wake(); aim(ev.clientX, ev.clientY); });
root.addEventListener('pointerleave', function () { gx = 0; gy = 0; });
send.addEventListener('click', function () { press(); });
resetIdle();
let rafId = 0;
let lastTs = -1;
let acc = 0;
let clock = 0;
function onResize() {
fitScene();
for (const f of resizeHooks) {
f();
}
draw();
}
fitScene();
window.addEventListener('resize', onResize);
function frame(ts) {
if (lastTs < 0) {
lastTs = ts;
}
// 탭이 숨었다 돌아와도 한 번에 100ms 까지만 따라잡는다 — 순간이동 대신 이어서 움직인다
acc += Math.min(ts - lastTs, 100);
lastTs = ts;
let n = 0;
while (acc >= FIXED_DT && n < 6) {
clock += FIXED_DT;
if (demo) {
demoTick(clock);
}
step();
acc -= FIXED_DT;
n += 1;
}
draw();
rafId = window.requestAnimationFrame(frame);
}
if (still) {
settle();
draw();
}
else {
rafId = window.requestAnimationFrame(frame);
}
return function () {
window.cancelAnimationFrame(rafId);
window.removeEventListener('resize', onResize);
};
})();// SendGlossSweepPointer - vanilla 판(06-send-btn-gloss-sweep-pointer) 의 React 포트. 같은 계산을 useEffect 안에서 돌린다.
import { useEffect, useRef } from "react";
import styles from "./SendGlossSweepPointer.module.scss";
const cx = (s: string): string => s.split(" ").map((n) => styles[n] ?? n).join(" ");
export default function SendGlossSweepPointer() {
const rootRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
const rootEl = rootRef.current;
if (!rootEl) return;
const root: HTMLElement = rootEl;
type RGB = [number, number, number];
const W = 480;
const H = 300;
const FIXED_DT = 16;
// 파스텔 팔레트 — 캔버스와 스크립트가 칠하는 색은 여기서만 고른다 (scss 쪽 색은 demo-tokens)
const INK: RGB = [38, 33, 52];
const PAPER: RGB = [255, 252, 246];
const CREAM: RGB = [255, 243, 224];
const SKY: RGB = [158, 208, 255];
const LILAC: RGB = [200, 184, 255];
const MINT: RGB = [156, 228, 204];
const PINK: RGB = [255, 182, 204];
const PEACH: RGB = [255, 214, 184];
function clamp(v: number, lo: number, hi: number): number { return v < lo ? lo : (v > hi ? hi : v); }
function lerp(a: number, b: number, t: number): number { return a + (b - a) * t; }
function easeOut(x: number): number { const c = clamp(x, 0, 1); return 1 - Math.pow(1 - c, 3); }
function easeInOut(x: number): number {
const c = clamp(x, 0, 1);
return c < 0.5 ? 4 * c * c * c : 1 - Math.pow(-2 * c + 2, 3) / 2;
}
function rgba(c: RGB, a: number): string {
return 'rgba(' + Math.round(c[0]) + ',' + Math.round(c[1]) + ',' + Math.round(c[2]) + ',' + clamp(a, 0, 1).toFixed(3) + ')';
}
function mix(a: RGB, b: RGB, t: number): RGB { return [lerp(a[0], b[0], t), lerp(a[1], b[1], t), lerp(a[2], b[2], t)]; }
// 시드 고정 난수 — 같은 시드면 같은 값이 다시 나온다 (32비트 정수 섞기)
function makeRng(seed: number): () => number {
let s = seed >>> 0;
return function (): number {
s = (s + 0x6d2b79f5) >>> 0;
let t = s;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const sceneEl = root.querySelector('[data-role="scene"]') as HTMLElement | null;
const statusEl = root.querySelector('[data-role="status"]') as HTMLElement | null;
if (!sceneEl || !statusEl) { return; }
const scene: HTMLElement = sceneEl;
const status: HTMLElement = statusEl;
const reduceQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
const still = reduceQuery.matches;
const resizeHooks: Array<() => void> = [];
// 자동 시연 중인가 — 사람이 처음 만지는 순간 시연을 멈추고 처음 상태로 돌린 뒤 상태 줄을 읽어 주기 시작한다
let demo = root.classList.contains('is-demo');
function wake(): void {
if (!demo) { return; }
demo = false;
root.classList.remove('is-demo');
status.setAttribute('aria-live', 'polite');
resetIdle();
}
function say(text: string): void {
if (status.textContent !== text) { status.textContent = text; }
}
// 장면 배율 — 480×300 좌표로 짠 판을 상자 폭에 맞춰 통째로 줄인다
let k = 1;
function fitScene(): void {
const w = root.clientWidth;
k = w > 0 ? w / W : 1;
scene.style.transform = 'scale(' + k.toFixed(4) + ')';
}
// 화면 좌표(CSS px) → 장면 좌표(480×300). 줄인 배율 k 로 나눠야 판 안의 위치가 된다
function toScene(clientX: number, clientY: number): [number, number] {
const r = root.getBoundingClientRect();
return [(clientX - r.left) / k, (clientY - r.top) / k];
}
// 캡처 단계에서 듣는다 — 버튼 자신의 pointerdown 보다 먼저 시연을 끝내야 사람의 첫 누름이 처음 상태에서 시작한다
root.addEventListener('pointerdown', wake, true);
root.addEventListener('keydown', wake, true);
type Phase = 'idle' | 'sending' | 'done';
// 버튼 자리(장면 px) — scss 의 .gl__send 위치·크기와 같은 값
const BTN_CX = 240;
const BTN_CY = 140;
const BTN_W = 232;
const BTN_H = 64;
// 광택 띠가 버튼을 한 번 가로지르는 시간
const SWEEP_MS = 820;
// 광택 띠 너비(px) — 대각으로 기울여(skewX −22°) 지나간다
const GLOSS_WIDTH = 46;
// 기울기가 포인터 쪽으로 다가가는 비율 — 16ms 한 걸음마다 남은 거리의 12% 만큼 간다(관성 lerp)
const TILT_LERP = 0.12;
const TILT_MAX_DEG = 14;
const SPOT = 140;
const SEND_MS = 1700;
const DEMO_CYCLE = 3000;
const TXT_IDLE = '결제하기';
const TXT_SENDING = '보내는 중';
const TXT_SENT = '결제 완료';
const TXT_READY = '결제할 준비 됨';
const TXT_SEND = '결제 요청을 보내는 중';
const TXT_DONE = '결제 완료 — 영수증을 메일로 보냈어요';
const sendEl = root.querySelector('[data-role="send"]') as HTMLButtonElement | null;
const labelEl = root.querySelector('[data-role="label"]') as HTMLElement | null;
const glossEl = root.querySelector('[data-role="gloss"]') as HTMLElement | null;
const spotEl = root.querySelector('[data-role="spot"]') as HTMLElement | null;
const shadowEl = root.querySelector('[data-role="shadow"]') as HTMLElement | null;
const glowEl = root.querySelector('[data-role="glow"]') as HTMLElement | null;
if (!sendEl || !labelEl || !glossEl || !spotEl || !shadowEl || !glowEl) { return; }
const glow: HTMLElement = glowEl;
const send: HTMLButtonElement = sendEl;
const label: HTMLElement = labelEl;
const gloss: HTMLElement = glossEl;
const spot: HTMLElement = spotEl;
const shadow: HTMLElement = shadowEl;
let phase: Phase = 'idle';
let pt = 0;
let tx = 0;
let ty = 0;
let gx = 0;
let gy = 0;
let demoNext = 200;
// 관성 lerp 한 걸음 — 목표로 곧장 가지 않고 남은 거리의 TILT_LERP 만큼만 간다
function follow(cur: number, goal: number): number { return cur + (goal - cur) * TILT_LERP; }
// 광택 띠의 x — 한 번 지나가는 동안 왼쪽 밖(−2×너비)에서 오른쪽 밖(버튼 너비 + 너비)까지
function glossX(t: number): number {
const p = (t % SWEEP_MS) / SWEEP_MS;
return lerp(-GLOSS_WIDTH * 2, BTN_W + GLOSS_WIDTH, easeInOut(p));
}
// 하이라이트 중심 — 포인터가 아니라 지금의 기울기(tx, ty)에서 다시 계산한다. 그래서 반사광도 늦게 따라온다
function spotCenter(): [number, number] { return [BTN_W / 2 + tx * BTN_W * 0.38, BTN_H / 2 + ty * BTN_H * 0.5]; }
function resetIdle(): void {
phase = 'idle';
pt = 0;
label.textContent = TXT_IDLE;
say(TXT_READY);
}
function finish(): void {
phase = 'done';
pt = 0;
label.textContent = TXT_SENT;
say(TXT_DONE);
}
function settle(): void { finish(); }
function press(): void {
if (phase === 'sending') { return; }
if (still) { finish(); return; }
phase = 'sending';
pt = 0;
label.textContent = TXT_SENDING;
say(TXT_SEND);
}
function aim(clientX: number, clientY: number): void {
const p = toScene(clientX, clientY);
gx = clamp((p[0] - BTN_CX) / (BTN_W / 2 + 40), -1, 1);
gy = clamp((p[1] - BTN_CY) / (BTN_H / 2 + 60), -1, 1);
}
function step(): void {
if (still) { tx = gx; ty = gy; return; }
tx = follow(tx, gx);
ty = follow(ty, gy);
if (phase !== 'sending') { return; }
pt += FIXED_DT;
if (pt >= SEND_MS) { finish(); }
}
function demoTick(t: number): void {
// 시연 포인터 — 버튼 둘레를 리사주 곡선으로 돈다
gx = 0.85 * Math.cos(t * 0.0021);
gy = 0.7 * Math.sin(t * 0.0033);
if (t < demoNext) { return; }
demoNext += DEMO_CYCLE;
resetIdle();
press();
}
function draw(): void {
send.style.transform = 'perspective(520px) rotateX(' + (-ty * TILT_MAX_DEG).toFixed(2) + 'deg) rotateY(' + (tx * TILT_MAX_DEG).toFixed(2) + 'deg)';
const c = spotCenter();
spot.style.transform = 'translate(' + (c[0] - SPOT / 2).toFixed(1) + 'px,' + (c[1] - SPOT / 2).toFixed(1) + 'px)';
spot.style.opacity = (0.45 + 0.4 * Math.min(1, Math.hypot(tx, ty))).toFixed(3);
// 그림자는 기울기 반대쪽으로 크게(가로 22px·세로 14px) 밀린다 — 같은 tx·ty 가 버튼 밖 넓은 바닥까지 전파된다
shadow.style.transform = 'translate(' + (-tx * 22).toFixed(1) + 'px,' + (14 - ty * 14).toFixed(1) + 'px) scale(' + (1 - Math.hypot(tx, ty) * 0.05).toFixed(3) + ')';
// 바닥 반사 — 광택 띠가 버튼 가운데를 지날 때 가장 밝다(띠 진행률의 사인). 위치는 기울기 쪽으로
let band = 0;
if (phase === 'sending') { band = Math.sin(Math.PI * ((pt % SWEEP_MS) / SWEEP_MS)); }
glow.style.transform = 'translate(' + (tx * 24).toFixed(1) + 'px,' + (ty * 10).toFixed(1) + 'px)';
glow.style.opacity = (0.2 + 0.6 * band).toFixed(3);
if (phase === 'sending') {
gloss.style.opacity = '';
gloss.style.transform = 'translateX(' + glossX(pt).toFixed(1) + 'px) skewX(-22deg)';
} else {
gloss.style.opacity = '0';
}
}
gloss.style.width = GLOSS_WIDTH + 'px';
root.addEventListener('pointermove', function (ev: PointerEvent): void { wake(); aim(ev.clientX, ev.clientY); });
root.addEventListener('pointerleave', function (): void { gx = 0; gy = 0; });
send.addEventListener('click', function (): void { press(); });
resetIdle();
let rafId = 0;
let lastTs = -1;
let acc = 0;
let clock = 0;
function onResize(): void {
fitScene();
for (const f of resizeHooks) { f(); }
draw();
}
fitScene();
window.addEventListener('resize', onResize);
function frame(ts: number): void {
if (lastTs < 0) { lastTs = ts; }
// 탭이 숨었다 돌아와도 한 번에 100ms 까지만 따라잡는다 — 순간이동 대신 이어서 움직인다
acc += Math.min(ts - lastTs, 100);
lastTs = ts;
let n = 0;
while (acc >= FIXED_DT && n < 6) {
clock += FIXED_DT;
if (demo) { demoTick(clock); }
step();
acc -= FIXED_DT;
n += 1;
}
draw();
rafId = window.requestAnimationFrame(frame);
}
if (still) {
settle();
draw();
} else {
rafId = window.requestAnimationFrame(frame);
}
return function (): void {
window.cancelAnimationFrame(rafId);
window.removeEventListener('resize', onResize);
};
}, []);
return (
<div className={cx("sb") + " is-demo"} ref={rootRef}>
<div className={cx("sb__scene")} data-role="scene">
<span className={cx("gl__glow")} data-role="glow" aria-hidden="true"></span>
<span className={cx("gl__shadow")} data-role="shadow" aria-hidden="true"></span>
<button className={cx("gl__send")} data-role="send" type="button">
<span className={cx("gl__spot")} data-role="spot" aria-hidden="true"></span>
<span className={cx("gl__gloss")} data-role="gloss" aria-hidden="true"></span>
<span className={cx("gl__label")} data-role="label">결제하기</span>
</button>
<p className={cx("sb__status")} data-role="status" aria-live="off">결제할 준비 됨</p>
</div>
</div>
);
}06 보내는 중 광택 띠가 지나가고 포인터 기울기를 따라 반사광이 옮겨 가는 버튼 — 측정 누적면적 17.132% · 움직인 프레임 23/23GODRICH 원작 · zip 에 SCSS·React 포함 · 버튼 애니메이션 효과 9종 — 전송 버튼이 접혀 날아가는 계산
이 데모가 속한 글
버튼 애니메이션 효과 9종 — 전송 버튼이 접혀 날아가는 계산전송 버튼은 눌린 뒤에도 '보냈다'를 보여 줘야 한다 — 01번은 버튼이 종이비행기로 접혀 곡선을 따라 기울며 날고, 02번은 스프링으로 눌렸다 튕기며 그림자 높이가 따라 바뀌고, 08번은 실패하면 점점 잦아드는 흔 이 글의 데모 전부 보기


