Communitygithub.com

骨架屏状态系统

设计一套系统化的“骨架屏”框架,通过将 UI “骨骼”映射到即将加载的内容,管理感知性能并防止布局偏移 (CLS)。

骨架屏状态系统 是什么?

该技能提供了一个系统化的方法论,用于设计界面的“加载中”状态。与通用的加载转圈或进度条不同,骨架屏使用低保真形状(“骨骼”)来模拟最终布局,这不仅减少了用户感知的等待时间,还能通过预先为即将加载的内容保留必要的页面空间,有效防止 **累积布局偏移 (CLS)**。该技能支持数据密集型仪表盘、内容信息流、图片网格、搜索视图以及单页应用等场景,并提供了从目标布局映射、骨骼层次定义、空间匹配、动效设计到过渡切换的完整工作流程。它还包含明确的不适用场景、决策规则(如300ms规则)、可访问性约束(如 `aria-hidden` 和 `aria-busy`)以及常见的失败模式分析,帮助开发者避免设计陷阱,构建出稳定且用户友好的加载体验。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/coastdigitalgroup/coastai-skills/tree/HEAD/website-design/skeleton-state-system

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

骨架屏状态系统 是做什么的?

目的

骨架屏状态系统提供了一种设计界面“加载中”状态的方法论。与通用的加载转圈或进度条不同,骨架屏使用“骨骼”(低保真形状)来近似最终布局,这能减少用户感知的等待时间,并通过在内容到达之前预留必要的空间来防止累积布局偏移 (CLS)。

使用场景

  • 数据密集型仪表盘: 多个小部件以不同速度加载的场景。
  • 内容信息流: 滚动浏览文章、产品或社交帖子列表。
  • 图片密集型网格: 为高分辨率图片预留空间,防止页面“跳动”。
  • 搜索与筛选视图: 提供系统正在处理查询的即时反馈。
  • 单页应用 (SPA): 管理异步获取数据时路由之间的过渡。

不适用的场景

  • 即时交互: 如果内容在 300ms 内加载完成,骨架屏可能会引起令人分心的“闪烁”。
  • 简单、低上下文加载: 对于单个按钮或小标签之类的小元素,标准的加载转圈或“加载中...”文字更为合适。
  • 静态内容: 硬编码或缓存并能立即渲染的内容。
  • 高速实时数据: 如果数据变化太快,导致骨架屏不断出现和消失,可能会引起视觉疲劳。

输入

  1. 目标布局: 组件或页面的最终“完全加载”设计。
  2. 内容变量: 用户界面的哪些部分是动态的(文本、图片、价格、头像)?
  3. 空间维度: 最终元素的确切高度、宽度和宽高比。
  4. 品牌基调: 用于“骨骼”基底和闪烁效果的主色和次要色。

输出

  1. 骨架蓝图: 展示骨骼排列方式的低保真地图。
  2. 骨骼规范: 形状(圆形 vs. 矩形)和尺寸(固定 vs. 百分比)的定义。
  3. 过渡策略: 骨架淡出和内容淡入的规则。
  4. 无障碍要求: 关于 aria-busy 和 aria-hidden 实施的指导。

工作流程

1. 映射“目标”几何形状

将最终组件分解为基本的几何基元:

  • 圆形: 用于头像、图标或圆角按钮。
  • 矩形(圆角): 用于卡片、图片容器和文本块。
  • 线条: 用于单行文本(标题、元数据)。

2. 定义骨骼层次

并非每个元素都需要骨骼。关注结构性的“锚点”:

  • 一级骨骼: 最大的视觉元素(例如,产品图片)。
  • 二级骨骼: 标题和主要的元数据。
  • 三级骨骼: 小的元细节或操作按钮(如果太小,通常可以省略)。

3. 建立空间匹配(CLS 规则)

确保骨架屏的尺寸与最终内容的容器完全匹配:

  • 宽高比: 为骨骼使用固定的宽高比(例如,视频用 16:9),这样在资源加载时其尺寸不会改变。
  • 文本尺寸: 使用与所代表文本的行高和近似宽度相匹配的骨骼。

4. 设计节奏与闪烁效果

骨架屏应感觉“生动”但不令人分心:

  • 基底颜色: 使用低对比度的中性颜色(例如,浅灰色)。
  • 闪烁效果(脉冲): 应用从右向左移动(应为从左到右,原文如此)的柔和渐变动画。
  • 同步: 如果屏幕上同时有多个骨架屏,确保它们的动画同步,以防止视觉混乱。
  • 减少动效: 将闪烁关键帧动画包裹在 @media (prefers-reduced-motion: reduce) 查询中,当用户偏好减少动效时禁用移动,并回退到静态或缓慢透明度脉冲的骨骼。

5. 定义“交接”过渡

规划骨架屏的退出:

  • 时机: 对真实内容使用短的淡入效果(例如,200ms),以防止生硬的“快照”过渡。
  • 交错: 对于列表,决定是让所有项目一次性出现,还是随着加载逐个出现。

决策规则

  • 300ms 规则: 仅当预计加载时间超过 300ms 时才显示骨架屏。
  • 骨骼精度: 骨骼应代表容器,而非特定的数据。例如,文本骨骼应是一个简单的条形,而不是模仿特定字母的锯齿线。
  • 行数模拟: 对于多行文本,使用 2 或 3 个宽度变化的骨骼(例如,最后一行宽度为 60%)来模拟自然段落流。
  • 加载转圈 vs. 骨架屏:
    • 对于页面级别或章节级别的过渡,使用骨架屏。
    • 对于小的局部操作(如“保存中...”按钮状态),使用加载转圈。

约束条件

  • 无障碍性: 骨架屏必须标记 aria-hidden="true",以便屏幕阅读器不会尝试“读取”空条形。父容器在加载时应使用 aria-busy="true",并且最好持有一个视觉上隐藏的 aria-live="polite" 区域,用于播报“加载中”,然后在内容替换骨架屏后播报完成状态——不要在骨骼本身使用 aria-live。对于闪烁效果,请遵循 prefers-reduced-motion。
  • 对比度: 骨架屏颜色必须与背景区分开,但对比度不能高到看起来像活动内容。
  • 响应式: 骨架骨骼必须使用与最终内容相同的网格/弹性布局逻辑进行缩放。

常见失败模式

  • “CLS 跳跃”: 200px 高的骨架屏被 300px 高的内容替换,导致页面“跳跃”。
  • 闪烁过度: 动画过快或对比度过高,引起晕动症或注意力分散。
  • 内容与骨骼不匹配: 为方形图片使用圆形骨骼,反之亦然。
  • 过度复杂: 试图为每个小图标都创建骨骼,导致布局混乱的“幽灵”布局。
  • “静态骨架屏”: 没有动画的骨架屏,可能被误认为是损坏或空白的页面。

验证标准

  • 骨架屏尺寸与最终“加载完成”状态完全匹配(零 CLS)。
  • 图片/视频的宽高比使用固定容器保留。
  • 闪烁动画柔和且从左到右移动。
  • 文本密集区域使用模拟自然行长度的骨骼。
  • 对骨架元素应用 aria-hidden="true",加载容器使用 aria-busy="true"。
  • 闪烁动画遵循 prefers-reduced-motion: reduce。
  • 从骨架屏到内容的过渡是平滑的淡入(约 200ms)。
  • 对于低于 300ms 的加载,不显示骨架屏。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for progressive disclosure using accordions, ensuring structural integrity, visual affordances, and accessibility across different content densities and devices.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for long-form content, managing readability, vertical rhythm, and information density to ensure a superior reading experience.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for informational elements that communicate state (Badges) and categorization (Tags) with clarity and accessibility.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for non-overlay notifications, managing global announcements and contextual inline alerts to communicate system states without interrupting the user's flow.

coastdigitalgroup/coastai-skills

Design and implement a systematic, asymmetrical bento-grid layout framework to organize diverse content types cohesively while maintaining strict visual hierarchy, logical focus order, and responsive flexibility.

coastdigitalgroup/coastai-skills

Design a responsive, mobile-first bottom navigation bar and persistent action dock system for mobile websites and web applications, establishing spatial anchors, tab bar anatomy, badge indicators, thumb-zone ergonomics, safe area inset handling, active/inactive state contrast, and desktop responsive adaptation rules.

coastdigitalgroup/coastai-skills

Design a mobile-first bottom sheet overlay system with configurable detents, drag affordances, safe area padding, responsive desktop modal/popover adaptation, and WCAG AA accessibility compliance.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for secondary navigation trails that provide orientation, context, and one-click access to parent levels in deep information architectures.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for buttons and interactive triggers, managing visual hierarchy, variant logic, and action grouping to ensure clear intent and accessible interaction.

coastdigitalgroup/coastai-skills

Design a systematic framework for date and time selection, managing calendar grids, range pickers, and scheduling interfaces to ensure precision and accessibility.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for modular content containers that maintain hierarchy, structural integrity, and action alignment across variable content and responsive viewports.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for horizontal discovery components, managing navigation affordances, scroll behavior, and accessibility to ensure effective content density without compromising usability.

coastdigitalgroup/coastai-skills

Design a systematic, highly accessible, and developer-friendly UI layout framework for code blocks, snippet showcases, multi-file code tabs, line-highlighting, diff views, and syntax token contrast in technical documentation and developer platforms.

coastdigitalgroup/coastai-skills

Design a systematic framework for global command menus (Cmd+K panels) that combines keyboard-driven navigation, command execution, and shortcut discovery into an accessible, responsive overlay.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for threaded conversations, managing nesting depths, action hierarchies, and community signaling to foster engagement and readability.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for side-by-side comparison interfaces, managing high attribute density and responsive complexity to support informed decision-making.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for user privacy, managing consent banners, preference centers, and persistent privacy controls to balance legal compliance with user trust.

coastdigitalgroup/coastai-skills

Design and implement a systematic, highly accessible, and responsive visual layout framework for conversational chat widgets, live chat boxes, and chatbot panels that ensures clear message scannability, native focus flow, and seamless mobile keyboard adaptation.

coastdigitalgroup/coastai-skills

Design a systematic, accessible, and high-conversion framework for custom select dropdowns and comboboxes, defining anatomy, states, search-filtering, and responsive mobile-adaptive patterns.

coastdigitalgroup/coastai-skills

Design and implement a systematic color palette that ensures WCAG 2.2 accessibility compliance. Trigger this skill when asked to define brand colors, create UI themes, or establish a visual system for a website.

相关技能