SkeletonSwap (骨架切换)
区域级的骨架与内容切换:超过 delay 才显示骨架、显示后至少停留 minDuration,交叉淡入淡出不跳动,服务端渲染时直接给出内容。
进入页面
默认插槽放真实内容,#skeleton 插槽放用 KunSkeleton 拼出的占位布局。loading 持续超过 delay(默认 150ms)才显示骨架,更快的请求直接出内容,不闪;骨架一旦出现至少停留 min-duration(默认 300ms)。等待期间骨架已按原尺寸排好、只是不可见,所以它出现时页面不会跳动。 创建时 loading 已为 false(服务端渲染等到了数据)就直接渲染内容,没有骨架也没有淡入。

《白色相簿2》全线路通关后的一点感想
鲲 · 3 条回复

求推荐剧情向、节奏慢一点的纯爱作品
雪之下 · 40 条回复

新人第一次玩 Galgame,该从哪部开始?
千恋万花 · 77 条回复
刷新已有内容
已有内容时重新加载,delay 内旧内容原样保留、仍可操作,快的请求看不到任何变化;超过 delay 才淡出成骨架,淡出中的旧内容是 inert。所以默认插槽在加载期间仍会渲染,要能用上一次的数据画出来。 触发加载的控件(如分页)放在组件外面,内容换掉时焦点才不会丢。

《白色相簿2》全线路通关后的一点感想
鲲 · 3 条回复

求推荐剧情向、节奏慢一点的纯爱作品
雪之下 · 40 条回复

新人第一次玩 Galgame,该从哪部开始?
千恋万花 · 77 条回复
布局与无障碍
根元素是一个真实的 div,两层叠在同一个 grid 单元格里交叉淡入淡出,不用定位也不用 z-index, 不会盖到区域外面;class 里的 display 会被覆盖,内容自己的布局写在插槽里。 加载期间根元素带 aria-busy="true",骨架层是 aria-hidden 且 inert。 需要读屏器在加载完成后播报时,自己在根元素上加 aria-live="polite";整页内容不要加。 淡入淡出只在 prefers-reduced-motion: no-preference 下进行。
属性
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| loading * | boolean | — | True while the region's data is loading. If it is false when the component is created, the default slot renders straight away, with no skeleton and no fade. |
| className | string | "" | Classes for the root. Its display is an inline grid that stacks the two layers, so a display class has no effect; lay the content out inside the slots. |
| delay | number | 150 | ms of loading before the skeleton shows. A load that ends sooner never shows it. While it waits, previous content stays as it is; with no content yet, the skeleton is laid out invisibly, so its arrival does not move the page. A server render and the hydration that follows skip the delay: they cannot wait it out. |
| minDuration | number | 300 | ms a shown skeleton stays before the content replaces it, so it does not flash on and off. |
插槽
| 插槽 | 作用域 | 说明 |
|---|---|---|
| #default | any | The real content. Also rendered while a reload waits out `delay`, so it must render from the previous data. |
| #skeleton | any | The placeholder layout, built from KunSkeleton, in the content's shape. |