正在加载…
Skeleton shimmer
扫光骨架屏
Sweep a highlight over loading placeholders.
Also searched as: 内容没出来时先显示灰色的占位块, 加载时灰块上有一道光扫过, 页面加载中的骨架占位, 卡片加载时的灰色闪光占位
- Placement
- Card list, Image
- Mood
- Soft, Crisp
- Trigger
- 一直循环
- Site types
- 个人网站, 博客, 工具和应用
How it works & accessibility
Move a gradient highlight across placeholder shapes while actual content is loading.
Best for: Card list, Image (一直循环).
Reduced motion: 不扫,只留静止的灰块(照样说明正在加载)
Mobile & touch: 和桌面一样;一屏的骨架往同一个方向扫
Key parameters
| Parameter | Key | Default | Range | Notes |
|---|---|---|---|---|
| 扫一次多久 | duration | 1500ms | — | — |
Ready-to-paste AI prompt
Add “Skeleton shimmer” to the card list in my project: Move a gradient highlight across placeholder shapes while actual content is loading.
Parameters: duration: 1500ms.
Preserve existing content and layout. Respect prefers-reduced-motion by showing the final state. Content must remain visible if JavaScript fails or is disabled.
Reference: https://donglang.linter.top/effects/skeleton.md (canonical specification and reference code).Dependency-free reference code
CSS
/* 扫光骨架屏(Skeleton shimmer)· 只用 CSS,不需要脚本。内容还没加载出来时,先摆出和内容一样形状的灰色占位块,一道光从左往右扫过,表示"正在加载"。
做法改写自 Motion Lexicon 的 skeleton-shimmer(MIT License,Copyright (c) 2026 Motion Lexicon contributors):光是盖在整个骨架上的一层,
用位移扫过去(交给显卡,不用每帧重画),外框是 role="status"、写明"正在加载";
扫一次 1.5 秒、一页上的骨架都往同一个方向扫、光不要太亮、和"一闪一闪"的脉冲二选一,学 Animation Handbook 的 Shimmer Effect(MIT License,Copyright (c) 2026 Matin Monshizadeh)。
用法:骨架的外框加 class="skeleton"(再加 role="status" aria-label="正在加载"),占位块加 class="sk",最后放 <span class="sk-shine" aria-hidden="true"></span>。
- 占位块照真内容的样子摆(头像、标题、两三行字),大小和真内容一样,换成真内容时页面不跳。
- 数据一到就把整个骨架换成真内容,不用等光扫完。
- 光是半透明的白色:盖在白底上看不见,盖在灰块上才亮一下。
- 深色的网站两个颜色都要换:灰块用白色低透明(--sk-base: rgb(255 255 255 / 0.08)),光也调淡(--sk-shine: rgb(255 255 255 / 0.1));
默认的灰块是 7% 的黑,放在深色底上就看不见了。
- 开启"减少动态"时:不扫,只留静止的灰块(照样说明"在加载")。 */
.skeleton {
--sk-duration: 1500ms;
--sk-base: rgb(0 0 0 / 0.07);
--sk-shine: rgb(255 255 255 / 0.75);
overflow: hidden;
}
/* 骨架自己写了定位(absolute 这些)就用它的:这一条写在 :where() 里,不和网站自己的写法比谁更具体 */
:where(.skeleton) { position: relative; }
.sk {
border-radius: 6px;
background: var(--sk-base);
}
.sk-shine {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 40%;
background: linear-gradient(90deg, transparent, var(--sk-shine), transparent);
translate: -100% 0;
pointer-events: none;
animation: sk-sweep var(--sk-duration) linear infinite;
}
@keyframes sk-sweep {
to { translate: 250% 0; }
}
@media (prefers-reduced-motion: reduce) {
.sk-shine { animation: none; }
}HTML
<!-- 扫光骨架屏:内容还没到时先放骨架(形状照真内容摆),数据一到就整个换成真内容 -->
<div class="skeleton" role="status" aria-label="正在加载">
<div class="sk" style="width: 48px; height: 48px; border-radius: 50%"></div>
<div class="sk" style="width: 60%; height: 14px; margin-top: 12px"></div>
<div class="sk" style="width: 90%; height: 10px; margin-top: 10px"></div>
<div class="sk" style="width: 80%; height: 10px; margin-top: 8px"></div>
<span class="sk-shine" aria-hidden="true"></span>
</div>
<script type="module">
// 数据到了:把骨架换成真内容(renderCard 换成自己的)
// const data = await fetch('/api/posts').then((r) => r.json());
// document.querySelector('.skeleton').replaceWith(renderCard(data));
</script>