按钮扫入填色
Button Hover Wipe
鼠标移入时,填色从按钮一侧扫过。
适用场景
适合需要方向感的主要操作按钮。 适合已有清晰边界的主按钮。填色扫过的过程中,文字和底色也要保持足够的对比。
应用示例
书店的新书预售页可以给描边的「立即预订」按钮加扫入填色。鼠标移到按钮上,深蓝色铺满按钮,读者能清楚地看到自己选中的操作。
AI 提示词
为【目标位置】添加 Button Hover Wipe(按钮扫入填色)。用位于文字下方的内嵌伪元素做横向缩放,检查扫入过程中各阶段的文字对比度。在减少动态效果模式下保持内容可读,并保留键盘操作。
示例代码
保存为 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;
}
.target {
position: relative;
display: grid;
place-items: center;
width: min(100%, 208px);
min-height: 84px;
padding: 10px;
color: #f5efff;
border: 1px solid #aa91ee80;
border-radius: 13px;
background: #29213f;
cursor: pointer;
font: 680 15px system-ui, sans-serif;
}
.target[aria-pressed="true"] { outline: 2px solid #d9c9ff; outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) {
.target, .target *, .target::before, .target::after, .target *::before, .target *::after {
transition: none !important;
animation: none !important;
}
}
.target { width: 164px; min-height: 54px; overflow: hidden; isolation: isolate; }
.target::before {
content: ''; position: absolute; inset: 0; z-index: -1; background: #6746a8;
transform: scaleX(0); transform-origin: left; transition: transform .28s ease-out;
}
.target:is(:hover, :focus-visible, [aria-pressed="true"])::before { transform: scaleX(1); }
</style>
</head>
<body>
<main class="demo">
<button class="target" type="button" aria-pressed="false" aria-label="打开作品"><span>打开作品</span></button>
</main>
<script>
const target = document.querySelector('.target');
target.addEventListener('click', () => {
target.setAttribute('aria-pressed', String(target.getAttribute('aria-pressed') !== 'true'));
});
</script>
</body>
</html>UI Skills 原创示例