骨架屏扫光
Skeleton Shimmer
内容加载时,一道柔和的亮光扫过占位的灰块。
适用场景
在信息流、图片或卡片返回前预留与正式内容接近的空间。 在已知最终排版时,让占位块的轮廓和间距对应真实内容,首屏加载期间也能看出页面会怎样排列。
应用示例
食谱列表加载时,先为每张卡的照片、菜名和用时各留一个占位块。微光从占位块扫过,数据到达后食谱直接填入对应位置。
也叫
- 骨架屏闪光
AI 提示词
给【目标内容】的加载阶段加上 Skeleton Shimmer。占位轮廓尽量贴近真实布局,让低对比高光扫过占位条。对辅助技术提供一个统一的加载状态,数据准备好后用真实内容替换骨架。减少动态效果模式下显示静态占位。
示例代码
保存为 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;
}
.skeleton {
width: min(100%, 242px);
padding: 16px;
border: 1px solid #4a4366;
border-radius: 16px;
background: #252139;
}
.skeleton-heading { display: flex; align-items: center; gap: 10px; }
.heading-lines, .skeleton-lines { display: grid; gap: 7px; }
.heading-lines { flex: 1; }
.skeleton-lines { margin-top: 15px; }
.placeholder {
display: block;
background: #413955 linear-gradient(105deg, transparent 27%, #8d7fb0 48%, transparent 69%) no-repeat;
background-size: 280px 100%;
background-position: -280px center;
border-radius: 5px;
animation: shimmer 1.65s ease-in-out infinite;
}
.avatar { width: 36px; height: 36px; border-radius: 50%; }
.title-line { width: 75%; height: 8px; }
.meta-line { width: 48%; height: 6px; }
.body-line { height: 6px; }
.body-line.short { width: 70%; }
@keyframes shimmer {
0% { background-position: -280px center; }
82%, 100% { background-position: 220px center; }
}
.loop-example {
display: grid;
gap: 12px;
justify-items: center;
width: min(100%, 290px);
}
.loop-example [data-motion] { animation-play-state: paused; }
.loop-example[data-playing] [data-motion] { animation-play-state: running; }
@media (prefers-reduced-motion: reduce) {
.loop-example [data-motion] { animation: none; }
.loop-example [data-loop-toggle] { display: none; }
}
</style>
</head>
<body>
<main class="demo">
<div class="loop-example">
<section class="skeleton" aria-label="个人资料加载中" aria-busy="true">
<div class="skeleton-heading" aria-hidden="true">
<span class="placeholder avatar" data-motion></span>
<div class="heading-lines">
<span class="placeholder title-line" data-motion></span>
<span class="placeholder meta-line" data-motion></span>
</div>
</div>
<div class="skeleton-lines" aria-hidden="true">
<span class="placeholder body-line" data-motion></span>
<span class="placeholder body-line short" data-motion></span>
</div>
</section>
<button class="demo-button" type="button" data-loop-toggle data-testid="effect-demo-loop-toggle">播放演示</button>
</div>
</main>
<script>
const example = document.querySelector('.loop-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 原创示例