網站導覽

v2.1.0
回饋

骨架畫面

先以即將載入的內容形狀預留版面,內容出現時頁面才不會跳動。

本頁內容

骨架以即將載入的內容形狀預留空間,避免內容出現時版面跳動。它是一塊採用膠囊標籤底色的區塊,上面有一道柔和的亮帶掃過。瀏覽器支援 sibling-index() 時,同一區塊內的骨架會依序啟動動畫,看起來就像一道亮帶從上往下掃過整個區塊。請依各自取代的內容設定骨架尺寸。若內容已經顯示,只是正在重新擷取,請使用忙碌狀態。

骨架畫面

<section class="flex items-center gap-sm" aria-busy="true" aria-label="Loading member">  <span class="skeleton skeleton-circle w(40)" aria-hidden="true"></span>  <div class="flex flex-col w-full text-sm" aria-hidden="true">    <span class="skeleton skeleton-text max-w(160)"></span>    <span class="skeleton skeleton-text max-w(320)"></span>  </div></section>
<section className="flex items-center gap-sm" aria-busy="true" aria-label="Loading member">  <span className="skeleton skeleton-circle w(40)" aria-hidden="true"></span>  <div className="flex flex-col w-full text-sm" aria-hidden="true">    <span className="skeleton skeleton-text max-w(160)"></span>    <span className="skeleton skeleton-text max-w(320)"></span>  </div></section>
<section class="flex items-center gap-sm" aria-busy="true" aria-label="Loading member">  <span class="skeleton skeleton-circle w(40)" aria-hidden="true"></span>  <div class="flex flex-col w-full text-sm" aria-hidden="true">    <span class="skeleton skeleton-text max-w(160)"></span>    <span class="skeleton skeleton-text max-w(320)"></span>  </div></section>
<template>  <section class="flex items-center gap-sm" aria-busy="true" aria-label="Loading member">    <span class="skeleton skeleton-circle w(40)" aria-hidden="true"></span>    <div class="flex flex-col w-full text-sm" aria-hidden="true">      <span class="skeleton skeleton-text max-w(160)"></span>      <span class="skeleton skeleton-text max-w(320)"></span>    </div>  </section></template>

#形狀

  • 單獨使用 skeleton 會產生區塊。將高度設成與要取代的圖片、圖表或卡片相同。
  • skeleton-text 代表一行文字。它與字形等高,並在所取代的行內垂直置中,讓載入後的文字落在同一套基線網格上。它會沿用周圍的字級與行高。
  • skeleton-circle 代表頭像或圖示。設定寬度後,高度會隨之調整。

載入中的卡片

<article class="card max-w(320) mx-auto" aria-busy="true" aria-label="Loading project">  <span class="skeleton card-media" aria-hidden="true"></span>  <div class="flex flex-col" aria-hidden="true">    <span class="skeleton skeleton-text max-w(160)"></span>    <span class="skeleton skeleton-text"></span>    <span class="skeleton skeleton-text max-w(240)"></span>  </div></article>
<article className="card max-w(320) mx-auto" aria-busy="true" aria-label="Loading project">  <span className="skeleton card-media" aria-hidden="true"></span>  <div className="flex flex-col" aria-hidden="true">    <span className="skeleton skeleton-text max-w(160)"></span>    <span className="skeleton skeleton-text"></span>    <span className="skeleton skeleton-text max-w(240)"></span>  </div></article>
<article class="card max-w(320) mx-auto" aria-busy="true" aria-label="Loading project">  <span class="skeleton card-media" aria-hidden="true"></span>  <div class="flex flex-col" aria-hidden="true">    <span class="skeleton skeleton-text max-w(160)"></span>    <span class="skeleton skeleton-text"></span>    <span class="skeleton skeleton-text max-w(240)"></span>  </div></article>
<template>  <article class="card max-w(320) mx-auto" aria-busy="true" aria-label="Loading project">    <span class="skeleton card-media" aria-hidden="true"></span>    <div class="flex flex-col" aria-hidden="true">      <span class="skeleton skeleton-text max-w(160)"></span>      <span class="skeleton skeleton-text"></span>      <span class="skeleton skeleton-text max-w(240)"></span>    </div>  </article></template>

#無障礙

  • 使用 aria-hidden="true" 對輔助技術隱藏骨架,並在骨架所在的區域加上 aria-busy="true" 和說明載入內容的標籤。
  • 使用者偏好減少動態效果時,亮帶會保持靜止,由骨架形狀提示內容仍在載入。
  • 只有在使用者可能察覺等待時才顯示骨架。等待時間很短時,請省略載入提示。若是按鈕,請使用 aria-busy 和旋轉指示器。

#類別

類別說明
skeleton預留區塊的高度應與所代替的圖片、圖表或卡片相同。
skeleton-text單行文字的骨架,高度與字形相同,並在原本的文字行內垂直置中。搭配 skeleton 使用
skeleton-circle用於頭像或圖示的圓形,大小由寬度決定搭配 skeleton 使用

#原始碼

@master/ui/components/skeleton.css
/* * Skeleton: the shape of content that is on its way. * A chip-toned block that a soft band of light crosses; with reduced motion it rests. * Hide it from assistive technology and mark the loading region with aria-busy. */@layer components.ui {  .skeleton {    display: block;    min-height: .75rem;    border-radius: calc(var(--radius-chip) * var(--corner-scale));    corner-shape: var(--corner-shape);    background:      linear-gradient(100deg, transparent 35%, var(--color-sheen) 50%, transparent 65%) 150% 0 / 300% 100% no-repeat,      var(--color-surface-chip);    color: transparent;    user-select: none;    -webkit-user-select: none;    pointer-events: none;    animation: skeleton-sweep 1.8s var(--easing-smooth) infinite;    /* The band crosses the way the words it stands for are read: from the right where they run from the right. */    &:dir(rtl) {      animation-direction: reverse;    }    /* One line of text: the block is as tall as the letters, centered in the line it stands for. */    &.skeleton-text {      height: .75em;      min-height: 0;      margin-block: calc((1lh - .75em) / 2);      border-radius: calc((var(--radius-chip) - 2px) * var(--corner-scale));    }    &.skeleton-circle {      aspect-ratio: 1;      border-radius: 999px;      corner-shape: round;    }    /* Lines in one block start one after another, so the band of light runs down the block as a single pass. */    @supports (width: calc(sibling-index() * 1px)) {      animation-delay: calc((sibling-index() - 1) * 90ms);    }    @media (prefers-reduced-motion: reduce) {      animation: none;    }    @media (forced-colors: active) {      outline: 1px solid GrayText;      outline-offset: -1px;    }  }}@keyframes skeleton-sweep {  to {    background-position: -50% 0, 0 0;  }}