Files
workspace/code/base-project/base-vue/test.html
T
2025-08-29 17:33:27 +08:00

110 lines
2.6 KiB
HTML

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>后台按钮渐深点击升级版</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
background: #f8f9fa;
}
.btn-group {
padding: 16px;
background: #fff;
border-radius: 6px;
min-width: 280px;
}
/* 基础按钮 */
.admin-btn {
position: relative;
overflow: hidden;
padding: 6px 14px;
border: none;
border-radius: 4px;
font-size: 13px;
font-weight: 500;
cursor: pointer;
color: #fff;
margin: 0 6px 6px 0;
outline: none;
transition: filter 0.2s ease;
}
/* 按钮颜色和overlay变量 */
.btn-primary {
background-color: #2563eb;
--overlay-color: rgba(0, 0, 0, 0.22);
}
.btn-secondary {
background-color: #1f2937;
--overlay-color: rgba(255, 255, 255, 0.12);
}
.btn-danger {
background-color: #ef4444;
--overlay-color: rgba(0, 0, 0, 0.18);
}
/* hover变浅 */
.admin-btn:hover {
filter: brightness(1.1);
}
/* 点击渐深叠加层 */
.admin-btn::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 0;
height: 100%;
background: linear-gradient(to right, rgba(0, 0, 0, 0), var(--overlay-color), rgba(0, 0, 0, 0));
pointer-events: none;
}
/* 点击触发动画 */
.admin-btn.active::after {
animation: tideDeep 0.35s ease-out forwards;
}
@keyframes tideDeep {
0% {
width: 0;
}
50% {
width: 100%;
}
100% {
width: 100%;
opacity: 0;
}
}
</style>
</head>
<body>
<div class="btn-group">
<button class="admin-btn btn-primary">保存修改</button>
<button class="admin-btn btn-secondary">取消</button>
<button class="admin-btn btn-danger">删除</button>
</div>
<script>
document.querySelectorAll('.admin-btn').forEach((btn) => {
btn.addEventListener('click', () => {
if (btn.classList.contains('active')) return
btn.classList.add('active')
btn.addEventListener(
'animationend',
() => {
btn.classList.remove('active')
},
{ once: true },
)
})
})
</script>
</body>
</html>