Circular Theme Reveal
圆形揭幕切换主题
An expanding circle reveals the next theme from the click point. Switching back closes the circle to reveal the original theme.
Where to use it
Add a spatial cue to a theme or palette switch in a dashboard or design tool. Use the switch as the origin when you want the user to see where a broad visual change began.
Practical example
A color design tool places a sun icon next to the canvas. Clicking it grows a light circle from the icon across the workspace, and switching back closes the circle to reveal the previous palette.
AI prompt
Add a Circular Theme Reveal to [theme toggle]. Layer the two themes inside the affected viewport and animate `clip-path: circle()` on the top layer. Start at the pointer or the center of the keyboard-activated button, calculate the maximum radius to the farthest corner, and preserve readable contrast throughout. Apply the theme immediately for reduced motion.
Example code
Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.
View HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Circular Theme Reveal</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.theme-scene {
width: min(100%, 282px); height: 138px; position: relative; isolation: isolate;
border-radius: 14px; overflow: hidden; border: 1px solid #75648f;
}
.theme-face {
position: absolute; inset: 0; padding: 11px 12px;
color: var(--theme-ink); background: var(--theme-bg);
}
.theme-dark { --theme-ink: #f0eaff; --theme-bg: #27224a; --theme-bar: #9987f2; --theme-line: #594b7f; --theme-green: #d0ecad; }
.theme-light {
--theme-ink: #36234d; --theme-bg: #f3ebff; --theme-bar: #815fc5; --theme-line: #d9c8ed; --theme-green: #3a7525;
clip-path: circle(0px at 92% 16%);
}
.theme-metric { margin: 0; font-size: 10px; font-weight: 650; }
.theme-number { margin: 5px 0 0; font-size: 23px; line-height: 1; font-weight: 760; }
.theme-number small { font-size: 10px; margin-left: 3px; color: var(--theme-green); }
.theme-chart {
height: 57px; margin-top: 11px; display: grid; grid-template-columns: repeat(11, 1fr);
align-items: end; gap: 4px; border-bottom: 1px solid var(--theme-line);
background: repeating-linear-gradient(0deg, transparent 0 17px, var(--theme-line) 17px 18px);
}
.theme-chart span {
display: block; height: var(--bar); border-radius: 3px 3px 0 0;
background: linear-gradient(0deg, color-mix(in srgb, var(--theme-bar), transparent 67%), var(--theme-bar));
}
.theme-toggle {
position: absolute; right: 9px; top: 7px; z-index: 1; width: 31px; height: 31px;
display: grid; place-items: center; color: #f5edff; background: #3a305b;
border-radius: 50%; border: 1px solid #a390ca; cursor: pointer; font-size: 18px;
}
.theme-toggle .theme-moon, .theme-scene[data-light="true"] .theme-sun { display: none; }
.theme-scene[data-light="true"] .theme-moon { display: inline; }
.theme-scene[data-light="true"] .theme-toggle { color: #513470; background: #e9dbfb; border-color: #a789c3; }
</style>
</head>
<body>
<main class="demo">
<div class="theme-scene" data-light="false">
<div class="theme-face theme-dark" aria-hidden="true">
<p class="theme-metric">Design subscriptions</p>
<p class="theme-number">1,284 <small>+18%</small></p>
<div class="theme-chart">
<span style="--bar: 29%"></span><span style="--bar: 38%"></span><span style="--bar: 32%"></span><span style="--bar: 49%"></span><span style="--bar: 45%"></span><span style="--bar: 57%"></span><span style="--bar: 61%"></span><span style="--bar: 70%"></span><span style="--bar: 65%"></span><span style="--bar: 79%"></span><span style="--bar: 82%"></span>
</div>
</div>
<div class="theme-face theme-light" aria-hidden="true">
<p class="theme-metric">Design subscriptions</p>
<p class="theme-number">1,284 <small>+18%</small></p>
<div class="theme-chart">
<span style="--bar: 29%"></span><span style="--bar: 38%"></span><span style="--bar: 32%"></span><span style="--bar: 49%"></span><span style="--bar: 45%"></span><span style="--bar: 57%"></span><span style="--bar: 61%"></span><span style="--bar: 70%"></span><span style="--bar: 65%"></span><span style="--bar: 79%"></span><span style="--bar: 82%"></span>
</div>
</div>
<button class="theme-toggle" type="button" aria-label="Light theme" aria-pressed="false" data-testid="circular-theme-toggle">
<span aria-hidden="true" class="theme-sun">☼</span><span aria-hidden="true" class="theme-moon">☾</span>
</button>
</div>
</main>
<script>
const scene = document.querySelector('.theme-scene');
const layer = scene.querySelector('.theme-light');
const button = scene.querySelector('.theme-toggle');
const reduced = matchMedia('(prefers-reduced-motion: reduce)');
let animation;
button.addEventListener('click', (event) => {
const bounds = layer.getBoundingClientRect();
const control = button.getBoundingClientRect();
const x = (event.detail ? event.clientX : control.left + control.width / 2) - bounds.left;
const y = (event.detail ? event.clientY : control.top + control.height / 2) - bounds.top;
const radius = Math.ceil(Math.hypot(Math.max(x, bounds.width - x), Math.max(y, bounds.height - y)));
const isLight = scene.dataset.light === 'false';
const finalClip = 'circle(' + (isLight ? radius : 0) + 'px at ' + x + 'px ' + y + 'px)';
const currentClip = animation?.playState === 'running'
? getComputedStyle(layer).clipPath
: 'circle(' + (isLight ? 0 : radius) + 'px at ' + x + 'px ' + y + 'px)';
animation?.cancel();
scene.dataset.light = String(isLight);
button.setAttribute('aria-pressed', String(isLight));
layer.style.clipPath = isLight ? 'none' : finalClip;
if (reduced.matches || typeof layer.animate !== 'function') return;
animation = layer.animate([{ clipPath: currentClip }, { clipPath: finalClip }], {
duration: 520, easing: 'cubic-bezier(.24, .72, .27, 1)',
});
});
reduced.addEventListener('change', () => animation?.cancel());
</script>
</body>
</html>Original example by UI Skills