成功彩屑
Success Confetti
彩色纸屑短暂散开,庆祝一个里程碑完成。
适用场景
用于完成新手引导或达成目标等有意义的节点。 把短促的彩屑留给值得庆祝的节点,动画结束后保留成就名称和后续操作入口。
应用示例
学员完成语言课程的最终测试后,证书卡周围喷出一阵彩屑。特效散去后,课程名和证书入口仍留在卡片上。
AI 提示词
【里程碑】完成时触发一次成功彩屑反馈。粒子不拦截操作并迅速消失,同时给出完成文案。减少动态效果模式下隐藏粒子。
示例代码
保存为 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;
}
.example { width: min(100%, 228px); position: relative; display: grid; gap: 10px; }
.panel { background: #292240; border: 1px solid #675785; border-radius: 11px; padding: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.label { margin: 0; font-size: 13px; font-weight: 650; }
.detail, .caption { margin: 0; color: #d7cbea; font-size: 11px; line-height: 1.35; }
.caption { text-align: center; }
.control { border: 1px solid #8874ae; background: #392e57; border-radius: 7px; padding: 5px 9px; min-height: 32px; color: #f6efff; cursor: pointer; font-size: 11px; font-weight: 650; }
.control:hover { background: #514174; }
.control.primary { color: #261b3f; background: #d1bfff; border-color: #e3d8ff; }
.control.primary:hover { background: #e3d8ff; }
.control:disabled { opacity: .55; cursor: default; }
.field { width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid #875fa8; border-radius: 6px; color: #f6efff; background: #1e1732; font-size: 12px; }
.field::placeholder { color: #c2abd8; }
[hidden] { display: none !important; }
.celebration { display: grid; justify-items: center; min-height: 98px; align-content: center; gap: 8px; }
.celebration p { min-height: 15px; }
.confetti-pieces { position: absolute; top: 42%; left: 50%; z-index: 1; pointer-events: none; }
.confetti-pieces i { position: absolute; width: 5px; height: 8px; border-radius: 2px; background: hsl(var(--hue) 88% 74%); opacity: 0; }
[data-burst] .confetti-pieces i { animation: burst .72s cubic-bezier(.12,.65,.32,1) both; }
@keyframes burst { 0% { opacity: 1; transform: scale(.4); } 65% { opacity: 1; } 100% { transform: translate(var(--x), var(--y)) rotate(var(--turn)); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
.example *, .example *::before, .example *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
</style>
</head>
<body>
<main class="demo">
<div class="example"><div class="celebration"><div class="confetti-pieces" aria-hidden="true"><i style="--x:34px;--y:0px;--hue:0deg;--turn:0deg"></i><i style="--x:38px;--y:18px;--hue:47deg;--turn:37deg"></i><i style="--x:31px;--y:39px;--hue:94deg;--turn:74deg"></i><i style="--x:13px;--y:57px;--hue:141deg;--turn:111deg"></i><i style="--x:-8px;--y:33px;--hue:188deg;--turn:148deg"></i><i style="--x:-26px;--y:33px;--hue:235deg;--turn:185deg"></i><i style="--x:-45px;--y:22px;--hue:282deg;--turn:222deg"></i><i style="--x:-58px;--y:0px;--hue:329deg;--turn:259deg"></i><i style="--x:-31px;--y:-15px;--hue:16deg;--turn:296deg"></i><i style="--x:-26px;--y:-33px;--hue:63deg;--turn:333deg"></i><i style="--x:-11px;--y:-49px;--hue:110deg;--turn:370deg"></i><i style="--x:13px;--y:-57px;--hue:157deg;--turn:407deg"></i><i style="--x:21px;--y:-27px;--hue:204deg;--turn:444deg"></i><i style="--x:38px;--y:-18px;--hue:251deg;--turn:481deg"></i></div><button class="control primary" type="button">庆祝</button><p class="detail" role="status"></p></div></div>
</main>
<script>
const demo = document.querySelector('.celebration');
const field = demo.querySelector('[role="status"]');
demo.querySelector('button').addEventListener('click', () => {
demo.removeAttribute('data-burst');
void demo.offsetWidth;
demo.setAttribute('data-burst', '');
field.textContent = "完成里程碑!";
});
</script>
</body>
</html>UI Skills 原创示例