媒体
热点标注
在图片上用标记点说明对应位置的内容,例如产品的各个部件或平面图上的位置。
本页内容
热点标注用图片上的标记说明对应位置的内容,例如产品的各个部件、平面图上的地点,或截图中值得留意的细节。热点容器包住图片,每个标记都是按百分比定位的按钮。标记可以打开按钮能打开的内容,因此打开弹出层无需脚本。
热点标注
<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 | 用于有无障碍名称的 button,呈现为直径 24px、带白边的墨色圆点,圆心位于 --x 和 --y。圆点内可显示数字,外圈会间歇向外扩散。指针悬停或圆点获得焦点时,动画暂停。 |
#自定义属性
| 属性 | 默认值 | 说明 |
|---|---|---|
--x | 标记的横向位置,以距图片左边缘的百分比表示在 hotspot-pin 上设置 | |
--y | 标记的纵向位置,以距图片上边缘的百分比表示在 hotspot-pin 上设置 |