媒體
圖片熱點
在圖片上加上標記,說明各處的內容,例如產品的各個部件或平面圖上的位置。
本頁內容
圖片熱點可用來標示產品的各個零件、平面圖上的位置,或螢幕擷取畫面中值得留意的細節。熱點容器包住圖片,每個標記都是以百分比定位的按鈕。標記沿用按鈕的原生行為,因此開啟彈出面板無須腳本。
圖片熱點
<figure class="figure hotspot w-full max-w(480)"> <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone hanging over two ranges of grey hills" style="--figure-ratio: 16 / 9"> <button class="hotspot-pin" type="button" style="--x: 72%; --y: 32%" popovertarget="spot-stone" aria-label="The stone"> 1 </button> <div class="popover" id="spot-stone" popover> <p class="m(0) fg-text-strong font-medium">The stone</p> <p class="m(0) fg-text-muted"> Moonstone, lit from above and slightly left, as every surface in the theme is. </p> </div> <button class="hotspot-pin" type="button" style="--x: 30%; --y: 62%" popovertarget="spot-hills" aria-label="The far hills"> 2 </button> <div class="popover" id="spot-hills" popover> <p class="m(0) fg-text-strong font-medium">The far hills</p> <p class="m(0) fg-text-muted">One step of the same grey lighter than the near ones.</p> </div></figure><figure className="figure hotspot w-full max-w(480)"> <img className="figure-media" src="/demo/moonstone.svg" alt="A pale stone hanging over two ranges of grey hills" style={{ '--figure-ratio': '16 / 9' } as React.CSSProperties} /> <button className="hotspot-pin" type="button" style={{ '--x': '72%', '--y': '32%' } as React.CSSProperties} popoverTarget="spot-stone" aria-label="The stone"> 1 </button> <div className="popover" id="spot-stone" popover=""> <p className="m(0) fg-text-strong font-medium">The stone</p> <p className="m(0) fg-text-muted"> Moonstone, lit from above and slightly left, as every surface in the theme is. </p> </div> <button className="hotspot-pin" type="button" style={{ '--x': '30%', '--y': '62%' } as React.CSSProperties} popoverTarget="spot-hills" aria-label="The far hills"> 2 </button> <div className="popover" id="spot-hills" popover=""> <p className="m(0) fg-text-strong font-medium">The far hills</p> <p className="m(0) fg-text-muted">One step of the same grey lighter than the near ones.</p> </div></figure><figure class="figure hotspot w-full max-w(480)"> <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone hanging over two ranges of grey hills" style="--figure-ratio: 16 / 9"> <button class="hotspot-pin" type="button" style="--x: 72%; --y: 32%" popovertarget="spot-stone" aria-label="The stone"> 1 </button> <div class="popover" id="spot-stone" popover> <p class="m(0) fg-text-strong font-medium">The stone</p> <p class="m(0) fg-text-muted"> Moonstone, lit from above and slightly left, as every surface in the theme is. </p> </div> <button class="hotspot-pin" type="button" style="--x: 30%; --y: 62%" popovertarget="spot-hills" aria-label="The far hills"> 2 </button> <div class="popover" id="spot-hills" popover> <p class="m(0) fg-text-strong font-medium">The far hills</p> <p class="m(0) fg-text-muted">One step of the same grey lighter than the near ones.</p> </div></figure><template> <figure class="figure hotspot w-full max-w(480)"> <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone hanging over two ranges of grey hills" style="--figure-ratio: 16 / 9"> <button class="hotspot-pin" type="button" style="--x: 72%; --y: 32%" popovertarget="spot-stone" aria-label="The stone"> 1 </button> <div class="popover" id="spot-stone" popover> <p class="m(0) fg-text-strong font-medium">The stone</p> <p class="m(0) fg-text-muted"> Moonstone, lit from above and slightly left, as every surface in the theme is. </p> </div> <button class="hotspot-pin" type="button" style="--x: 30%; --y: 62%" popovertarget="spot-hills" aria-label="The far hills"> 2 </button> <div class="popover" id="spot-hills" popover> <p class="m(0) fg-text-strong font-medium">The far hills</p> <p class="m(0) fg-text-muted">One step of the same grey lighter than the near ones.</p> </div> </figure></template>按一下標記。
#標記定位
hotspot 讓圖片的外層元素與圖片同寬,並成為標記的定位基準。每個 hotspot-pin 在自己的樣式中設定 --x 和 --y,以圖片左上角為原點,分別用圖片寬度和高度的百分比指定位置,讓標記中心對準該點。使用百分比可讓標記在圖片縮放時維持在同一處。
標記使用 <button>,若要導向其他位置則使用連結。使用 popovertarget 可開啟彈出面板。瀏覽器支援錨點定位時,會將彈出面板放在標記旁,否則會放在檢視區中央。使用 interestfor 時,指標停留在標記上或標記取得焦點,就會顯示工具提示。
#標記
標記是直徑 24px 的圓形,以文字色填滿,並帶有白色外框與外側的深色陰影。圖片本身不隨主題變化,因此兩種主題都沿用相同的外框和陰影,讓標記在淺色和深色圖片上都清楚可見。標記可加上編號,對應文字清單中的相同項目,也可留空。
每隔幾秒會有一圈波紋從標記向外擴散,提示使用者可以按下標記。啟用減少動態效果的偏好設定時,波紋會保持靜止。在觸控螢幕上,標記維持原本大小,可點按範圍則擴大至 44px。
無編號標記
<figure class="figure hotspot w-full max-w(360)"> <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone hanging over two ranges of grey hills" style="--figure-ratio: 16 / 9"> <button class="hotspot-pin" type="button" style="--x: 72%; --y: 32%" popovertarget="plain-stone" aria-label="The stone"></button> <div class="popover" id="plain-stone" popover>The stone the light theme is named for.</div> <button class="hotspot-pin" type="button" style="--x: 22%; --y: 78%" popovertarget="plain-hills" aria-label="The near hills"></button> <div class="popover" id="plain-hills" popover>The near hills, in the ink of the page.</div></figure><figure className="figure hotspot w-full max-w(360)"> <img className="figure-media" src="/demo/moonstone.svg" alt="A pale stone hanging over two ranges of grey hills" style={{ '--figure-ratio': '16 / 9' } as React.CSSProperties} /> <button className="hotspot-pin" type="button" style={{ '--x': '72%', '--y': '32%' } as React.CSSProperties} popoverTarget="plain-stone" aria-label="The stone"></button> <div className="popover" id="plain-stone" popover="">The stone the light theme is named for.</div> <button className="hotspot-pin" type="button" style={{ '--x': '22%', '--y': '78%' } as React.CSSProperties} popoverTarget="plain-hills" aria-label="The near hills"></button> <div className="popover" id="plain-hills" popover="">The near hills, in the ink of the page.</div></figure><figure class="figure hotspot w-full max-w(360)"> <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone hanging over two ranges of grey hills" style="--figure-ratio: 16 / 9"> <button class="hotspot-pin" type="button" style="--x: 72%; --y: 32%" popovertarget="plain-stone" aria-label="The stone"></button> <div class="popover" id="plain-stone" popover>The stone the light theme is named for.</div> <button class="hotspot-pin" type="button" style="--x: 22%; --y: 78%" popovertarget="plain-hills" aria-label="The near hills"></button> <div class="popover" id="plain-hills" popover>The near hills, in the ink of the page.</div></figure><template> <figure class="figure hotspot w-full max-w(360)"> <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone hanging over two ranges of grey hills" style="--figure-ratio: 16 / 9"> <button class="hotspot-pin" type="button" style="--x: 72%; --y: 32%" popovertarget="plain-stone" aria-label="The stone"></button> <div class="popover" id="plain-stone" popover>The stone the light theme is named for.</div> <button class="hotspot-pin" type="button" style="--x: 22%; --y: 78%" popovertarget="plain-hills" aria-label="The near hills"></button> <div class="popover" id="plain-hills" popover>The near hills, in the ink of the page.</div> </figure></template>#無障礙
- 每個標記都需要可存取名稱,說明它指向什麼,例如
aria-label="The arm"。請用具體的名稱,避免只寫「標記 1」或只提供標記內的數字。 - 按 Tab 會依標記在文件中出現的順序移動焦點,因此請依讀者查看圖片的順序撰寫標記。
- 圖片的
alt用來描述整張圖片。請在圖片下方以相同編號列出各標記的說明,讓讀者也能直接從文字取得資訊。 - 若圖片可能在手機上瀏覽,請讓標記彼此至少相距 44px,避免點按範圍重疊。
#類別
| 類別 | 說明 |
|---|---|
hotspot | 與圖片同寬的外框,圖釘以此外框為定位基準 |
hotspot-pin | 標記使用具有無障礙名稱的按鈕,呈現為帶白邊的 24px 前景色實心圓。圓心由 --x 和 --y 定位,圓內可顯示數字。圓環會不時向外擴散,指標停在標記上或標記取得焦點時會暫停。 |
#自訂屬性
| 屬性 | 預設值 | 說明 |
|---|---|---|
--x | 圖釘的水平位置,以距圖片左邊緣的百分比表示。設定於 hotspot-pin | |
--y | 圖釘的垂直位置,以距圖片上邊緣的百分比表示。設定於 hotspot-pin |