08クリック座標の値が広がる円形マスクパネル
クリックしたタブラベルの中心座標を新パネルのclip-path circle()の中心点として渡し、半径の値を0からパネル対角線の長さまで広げることで、その地点から円形に染み出すように現れる。
使いどころランディングページの機能タブ・プロモバナーパネル
clipPathcircle()getBoundingClientRect()

<main class="stage">
<div class="mr is-demo" id="mr">
<div class="mr__tabs" role="tablist" aria-label="機能タブ">
<button type="button" class="mr__tab is-active" role="tab" id="mr-tab-0" aria-selected="true" aria-controls="mr-panel-0" data-idx="0">速度</button>
<button type="button" class="mr__tab" role="tab" id="mr-tab-1" aria-selected="false" aria-controls="mr-panel-1" data-idx="1" tabindex="-1">セキュリティ</button>
<button type="button" class="mr__tab" role="tab" id="mr-tab-2" aria-selected="false" aria-controls="mr-panel-2" data-idx="2" tabindex="-1">コラボレーション</button>
</div>
<div class="mr__wrap" id="mrWrap">
<div class="mr__panel is-active" id="mr-panel-0" role="tabpanel" aria-labelledby="mr-tab-0" tabindex="0"><span class="mr__num">01</span><p class="mr__line">応答速度120ms</p></div>
<div class="mr__panel" id="mr-panel-1" role="tabpanel" aria-labelledby="mr-tab-1" tabindex="0" hidden><span class="mr__num">02</span><p class="mr__line">二段階認証対応</p></div>
<div class="mr__panel" id="mr-panel-2" role="tabpanel" aria-labelledby="mr-tab-2" tabindex="0" hidden><span class="mr__num">03</span><p class="mr__line">リアルタイム共同編集</p></div>
</div>
<p class="mr__meta">半径 <b id="mrR">0</b>px</p>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 계산 겹: index.html 의 select() 가 클릭(또는 키보드 이동)된 탭 라벨의 중심 좌표를 clip-path circle() 의
// 중심점으로 쓰고, 반경 목표값은 Math.hypot(wrap.width, wrap.height) 로 구한 패널 대각선 길이다.
@include stage($stage-paper);
.mr { width: min(100%, 300px); min-width: 0; display: flex; flex-direction: column; gap: $sp-3; }
.mr__tabs { display: flex; gap: $sp-1; background: rgba($subject-blue-deep, .08); padding: $sp-1; border-radius: $r-pill; }
.mr__tab {
flex: 1 1 0; border: none; background: transparent; border-radius: $r-pill; cursor: pointer;
padding: $sp-2 $sp-2; font-size: 11px; font-weight: 700; color: rgba($subject-ink, .64);
}
.mr__tab.is-active { background: $subject-blue-deep; color: $subject-cream; }
.mr__tab:focus-visible { outline: 2px solid $subject-blue-deep; outline-offset: 2px; }
.mr__wrap { position: relative; min-width: 0; height: 140px; border-radius: $r-card; background: $subject-cream; overflow: hidden; box-shadow: 0 6px 18px rgba($subject-ink, .1); }
.mr__panel {
position: absolute; inset: 0; box-sizing: border-box; padding: $sp-4;
display: flex; flex-direction: column; align-items: center; justify-content: center; gap: $sp-2;
opacity: 0; pointer-events: none;
}
.mr__panel.is-active { opacity: 1; pointer-events: auto; z-index: 1; }
.mr__panel.is-front { opacity: 1; pointer-events: auto; z-index: 2; transition: clip-path $dur-enter $ease-out; }
.mr__num { font-size: 30px; font-weight: 800; color: $subject-blue-deep; }
.mr__line { margin: 0; font-size: 12px; color: rgba($subject-ink, .72); }
.mr__meta { margin: 0; font-size: 11px; color: rgba($subject-ink, .6); text-align: center; }
.mr__meta b { color: $subject-blue-deep; font-weight: 700; }
@media (max-width: 340px) {
.mr { width: 100%; gap: $sp-2; }
.mr__tab { padding: $sp-1 $sp-2; }
.mr__wrap { height: 96px; }
.mr__num { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) {
.mr__panel.is-front { transition: none; }
}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);
}
.mr {
width: min(100%, 300px);
min-width: 0;
display: flex;
flex-direction: column;
gap: 12px;
}
.mr__tabs {
display: flex;
gap: 4px;
background: rgba(10, 79, 232, 0.08);
padding: 4px;
border-radius: 999px;
}
.mr__tab {
flex: 1 1 0;
border: none;
background: transparent;
border-radius: 999px;
cursor: pointer;
padding: 8px 8px;
font-size: 11px;
font-weight: 700;
color: rgba(23, 20, 26, 0.64);
}
.mr__tab.is-active {
background: #0a4fe8;
color: #fff7e6;
}
.mr__tab:focus-visible {
outline: 2px solid #0a4fe8;
outline-offset: 2px;
}
.mr__wrap {
position: relative;
min-width: 0;
height: 140px;
border-radius: 16px;
background: #fff7e6;
overflow: hidden;
box-shadow: 0 6px 18px rgba(23, 20, 26, 0.1);
}
.mr__panel {
position: absolute;
inset: 0;
box-sizing: border-box;
padding: 16px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 8px;
opacity: 0;
pointer-events: none;
}
.mr__panel.is-active {
opacity: 1;
pointer-events: auto;
z-index: 1;
}
.mr__panel.is-front {
opacity: 1;
pointer-events: auto;
z-index: 2;
transition: clip-path 600ms ease-out;
}
.mr__num {
font-size: 30px;
font-weight: 800;
color: #0a4fe8;
}
.mr__line {
margin: 0;
font-size: 12px;
color: rgba(23, 20, 26, 0.72);
}
.mr__meta {
margin: 0;
font-size: 11px;
color: rgba(23, 20, 26, 0.6);
text-align: center;
}
.mr__meta b {
color: #0a4fe8;
font-weight: 700;
}
@media (max-width: 340px) {
.mr {
width: 100%;
gap: 8px;
}
.mr__tab {
padding: 4px 8px;
}
.mr__wrap {
height: 96px;
}
.mr__num {
font-size: 24px;
}
}
@media (prefers-reduced-motion: reduce) {
.mr__panel.is-front {
transition: none;
}
}(function () {
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var COUNT = 3;
var HOLD_MS = 900;
var root = document.getElementById('mr');
var wrap = document.getElementById('mrWrap');
var rEl = document.getElementById('mrR');
var tabs = [0, 1, 2].map(function (i) { return document.getElementById('mr-tab-' + i); });
var panels = [0, 1, 2].map(function (i) { return document.getElementById('mr-panel-' + i); });
var isDemo = true;
var active = 0;
var busy = false;
function human() {
if (isDemo) { root.classList.remove('is-demo'); isDemo = false; }
}
function select(idx) {
if (idx === active || busy) return;
busy = true;
var tabRect = tabs[idx].getBoundingClientRect();
var wrapRect = wrap.getBoundingClientRect();
var cx = tabRect.left + tabRect.width / 2 - wrapRect.left; // 계산 겹: 탭 라벨 중심 좌표 → 마스크 중심
var cy = tabRect.top + tabRect.height / 2 - wrapRect.top;
var r = Math.hypot(wrapRect.width, wrapRect.height); // 계산 겹: 패널 대각선 길이 = 半径 목표값
var incoming = panels[idx];
var outgoing = panels[active];
incoming.style.transition = 'none';
incoming.style.clipPath = 'circle(0px at ' + cx.toFixed(1) + 'px ' + cy.toFixed(1) + 'px)';
incoming.removeAttribute('hidden');
incoming.classList.add('is-front');
incoming.getBoundingClientRect();
incoming.style.transition = '';
rEl.textContent = '0';
tabs[active].classList.remove('is-active');
tabs[active].setAttribute('aria-selected', 'false');
tabs[active].setAttribute('tabindex', '-1');
tabs[idx].classList.add('is-active');
tabs[idx].setAttribute('aria-selected', 'true');
tabs[idx].setAttribute('tabindex', '0');
requestAnimationFrame(function () {
incoming.style.clipPath = 'circle(' + r.toFixed(1) + 'px at ' + cx.toFixed(1) + 'px ' + cy.toFixed(1) + 'px)';
rEl.textContent = String(Math.round(r));
});
function onEnd(e) {
if (e.propertyName !== 'clip-path') return;
incoming.removeEventListener('transitionend', onEnd);
incoming.classList.add('is-active');
incoming.classList.remove('is-front');
incoming.style.clipPath = 'none';
outgoing.classList.remove('is-active');
outgoing.setAttribute('hidden', '');
active = idx;
busy = false;
}
incoming.addEventListener('transitionend', onEnd);
}
tabs.forEach(function (t, i) {
t.addEventListener('click', function () { human(); select(i); });
});
root.addEventListener('keydown', function (e) {
var idx = tabs.indexOf(document.activeElement);
if (idx === -1) return;
var next = null;
if (e.key === 'ArrowRight') next = (idx + 1) % COUNT;
else if (e.key === 'ArrowLeft') next = (idx - 1 + COUNT) % COUNT;
else if (e.key === 'Home') next = 0;
else if (e.key === 'End') next = COUNT - 1;
if (next === null) return;
e.preventDefault();
human();
tabs[next].focus({ preventScroll: true });
select(next);
});
function loop() {
if (!isDemo) return;
select((active + 1) % COUNT);
window.setTimeout(loop, HOLD_MS);
}
if (!reduce) {
window.setTimeout(loop, HOLD_MS);
} else {
root.classList.remove('is-demo');
}
})();// TabMaskRevealRadial — vanilla 판(run/394/demo/08-tab-panel-mask-reveal-radial/index.html) 의 React 포트.
// select() 가 클릭(또는 키보드 이동)된 탭 라벨의 중심 좌표를 clip-path circle() 의 중심점으로 쓰고,
// 반경 목표값은 Math.hypot(wrap.width, wrap.height) 로 구한 패널 대각선 길이다.
import { useEffect, useRef } from "react";
import styles from "./TabMaskRevealRadial.module.scss";
type Box<T> = { current: T };
const HOLD_MS = 900;
const COUNT = 3;
export default function TabMaskRevealRadial() {
const rootRef = useRef(null) as unknown as Box<HTMLDivElement>;
const wrapRef = useRef(null) as unknown as Box<HTMLDivElement>;
const rEl = useRef(null) as unknown as Box<HTMLElement>;
const tabRefs = useRef([null, null, null]) as unknown as Box<(HTMLButtonElement | null)[]>;
const panelRefs = useRef([null, null, null]) as unknown as Box<(HTMLDivElement | null)[]>;
const timerRef = useRef(0) as unknown as Box<number>;
useEffect(() => {
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
let isDemo = true;
let active = 0;
let busy = false;
function human() {
if (isDemo) { rootRef.current?.classList.remove(styles.isDemo); isDemo = false; }
}
function select(idx: number) {
if (idx === active || busy) return;
const wrap = wrapRef.current, tab = tabRefs.current[idx];
const incoming = panelRefs.current[idx], outgoing = panelRefs.current[active];
if (!wrap || !tab || !incoming || !outgoing) return;
busy = true;
const tabRect = tab.getBoundingClientRect();
const wrapRect = wrap.getBoundingClientRect();
const cx = tabRect.left + tabRect.width / 2 - wrapRect.left; // 계산 겹: 탭 라벨 중심 좌표 → 마스크 중심
const cy = tabRect.top + tabRect.height / 2 - wrapRect.top;
const r = Math.hypot(wrapRect.width, wrapRect.height); // 계산 겹: 패널 대각선 길이 = 반경 목표값
incoming.style.transition = "none";
incoming.style.clipPath = "circle(0px at " + cx.toFixed(1) + "px " + cy.toFixed(1) + "px)";
incoming.removeAttribute("hidden");
incoming.classList.add(styles.isFront);
incoming.getBoundingClientRect();
incoming.style.transition = "";
if (rEl.current) rEl.current.textContent = "0";
const prevTab = tabRefs.current[active], nextTab = tabRefs.current[idx];
prevTab?.classList.remove(styles.isActive);
prevTab?.setAttribute("aria-selected", "false");
prevTab?.setAttribute("tabindex", "-1");
nextTab?.classList.add(styles.isActive);
nextTab?.setAttribute("aria-selected", "true");
nextTab?.setAttribute("tabindex", "0");
requestAnimationFrame(() => {
incoming.style.clipPath = "circle(" + r.toFixed(1) + "px at " + cx.toFixed(1) + "px " + cy.toFixed(1) + "px)";
if (rEl.current) rEl.current.textContent = String(Math.round(r));
});
function onEnd(e: TransitionEvent) {
if (e.propertyName !== "clip-path") return;
incoming!.removeEventListener("transitionend", onEnd as EventListener);
incoming!.classList.add(styles.isActive);
incoming!.classList.remove(styles.isFront);
incoming!.style.clipPath = "none";
outgoing!.classList.remove(styles.isActive);
outgoing!.setAttribute("hidden", "");
active = idx;
busy = false;
}
incoming.addEventListener("transitionend", onEnd as EventListener);
}
function onKeydown(e: KeyboardEvent) {
const idx = tabRefs.current.indexOf(document.activeElement as HTMLButtonElement);
if (idx === -1) return;
let next: number | null = null;
if (e.key === "ArrowRight") next = (idx + 1) % COUNT;
else if (e.key === "ArrowLeft") next = (idx - 1 + COUNT) % COUNT;
else if (e.key === "Home") next = 0;
else if (e.key === "End") next = COUNT - 1;
if (next === null) return;
e.preventDefault();
human();
tabRefs.current[next]?.focus({ preventScroll: true });
select(next);
}
function onTabClick(i: number) { return () => { human(); select(i); }; }
const clickHandlers = [0, 1, 2].map(onTabClick);
tabRefs.current.forEach((t, i) => t?.addEventListener("click", clickHandlers[i]));
rootRef.current?.addEventListener("keydown", onKeydown);
function loop() {
if (!isDemo) return;
select((active + 1) % COUNT);
timerRef.current = window.setTimeout(loop, HOLD_MS);
}
if (!reduce) {
timerRef.current = window.setTimeout(loop, HOLD_MS);
} else {
rootRef.current?.classList.remove(styles.isDemo);
}
return () => {
window.clearTimeout(timerRef.current);
tabRefs.current.forEach((t, i) => t?.removeEventListener("click", clickHandlers[i]));
rootRef.current?.removeEventListener("keydown", onKeydown);
};
}, []);
const feats = [
{ name: "속도", num: "01", line: "응답 속도 120ms" },
{ name: "보안", num: "02", line: "2단계 인증 지원" },
{ name: "협업", num: "03", line: "실시간 공동 편집" },
];
return (
<main className={styles.stage}>
<div className={styles.mr + " " + styles.isDemo} ref={rootRef}>
<div className={styles.tabs} role="tablist" aria-label="기능 탭">
{feats.map((f, i) => (
<button
key={f.name}
type="button"
className={styles.tab + (i === 0 ? " " + styles.isActive : "")}
role="tab"
aria-selected={i === 0 ? "true" : "false"}
tabIndex={i === 0 ? 0 : -1}
ref={(el: HTMLButtonElement | null) => { tabRefs.current[i] = el; }}
>{f.name}</button>
))}
</div>
<div className={styles.wrap} ref={wrapRef}>
{feats.map((f, i) => (
<div
key={f.name}
className={styles.panel + (i === 0 ? " " + styles.isActive : "")}
role="tabpanel"
tabIndex={0}
hidden={i !== 0}
ref={(el: HTMLDivElement | null) => { panelRefs.current[i] = el; }}
>
<span className={styles.num}>{f.num}</span>
<p className={styles.line}>{f.line}</p>
</div>
))}
</div>
<p className={styles.meta}>
반경 <b ref={rEl}>0</b>px
</p>
</div>
</main>
);
}08 クリック座標の値が広がる円形マスクパネル — 計測 累積面積 6.911% · 動いたフレーム 8/23GODRICH オリジナル · SCSS と React は zip に同梱 · css タブ 切り替え ふわっと 9パターン — コードそのまま
このデモが属する記事
css タブ 切り替え ふわっと 9パターン — コードそのままcss タブ 切り替え ふわっと の9パターンは、それぞれ違う値を計算の起点にしています。高さモーフは2枚のパネルの実測ピクセル差で伸びる時間を決め、スタック型はアクティブタブとのインデックス距離で縮小率を決め、弾性スライドはバネ定数で弾ん この記事のデモをすべて見る


