呼吸光
Breathing Glow
元素尺寸固定,周围的光晕缓慢增强再减弱。
适用场景
给正在监听的控件或状态显示增加柔和的提示。 在光晕旁放一个稳定的图标或文字状态,让用户在明暗循环的任何时刻都能看懂含义。
应用示例
语言陪练开始收音后显示「正在听」。此时麦克风周围的光晕缓缓变亮再变暗,录音停止时恢复成固定轮廓。
AI 提示词
给【目标】加呼吸光。把固定的光晕放在伪元素上,三秒内让透明度在 0.25 和 0.85 之间往返。保持文字对比度,减少动态时使用固定的低亮度光晕。
示例代码
保存为 HTML 文件后,用浏览器打开即可运行。代码与页面里的演示一致。
查看 HTML
<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>呼吸光</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;
}
.glow-label {
position: relative; display: grid; place-items: center;
width: 120px; height: 40px; border-radius: 999px; border: 1px solid #8e75dc;
background: #392a69; font-weight: 700; font-size: 14px;
}
.glow-halo {
position: absolute; inset: 0; z-index: -1; opacity: .35; border-radius: inherit;
box-shadow: 0 0 27px 12px #9569fe; animation: breathe 3s ease-in-out infinite;
}
@keyframes breathe { 50% { opacity: .85; } }
.motion-example { display: grid; justify-items: center; width: 100%; gap: 10px; }
.motion-specimen {
display: grid;
place-items: center;
width: min(100%, 295px);
height: 108px;
position: relative;
isolation: isolate;
}
.motion-example [data-motion] { animation-play-state: paused; }
.motion-example[data-playing] [data-motion] { animation-play-state: running; }
@media (prefers-reduced-motion: reduce) {
.motion-example [data-motion] { animation: none; }
.motion-example [data-loop-toggle] { display: none; }
}
</style>
</head>
<body>
<main class="demo">
<div class="motion-example">
<div class="motion-specimen" aria-hidden="true"><span class="glow-label"><span class="glow-halo" data-motion></span>监听中</span></div>
<button class="demo-button" type="button" data-loop-toggle data-testid="effect-demo-loop-toggle">播放演示</button>
</div>
</main>
<script>
const example = document.querySelector('.motion-example');
const toggle = example.querySelector('[data-loop-toggle]');
toggle.addEventListener('click', () => {
const playing = example.toggleAttribute('data-playing');
toggle.textContent = playing ? "暂停演示" : "播放演示";
});
</script>
</body>
</html>UI Skills 原创示例