导航

v2.1.0
媒体

热点标注

在图片上用标记点说明对应位置的内容,例如产品的各个部件或平面图上的位置。

本页内容

热点标注用图片上的标记说明对应位置的内容,例如产品的各个部件、平面图上的地点,或截图中值得留意的细节。热点容器包住图片,每个标记都是按百分比定位的按钮。标记可以打开按钮能打开的内容,因此打开弹出层无需脚本。

热点标注

<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 上设置

#源码

@master/ui/components/hotspot.css
/* * Hotspot: points on a picture that say what is there. * The hotspot is the frame around a picture; each pin is a button placed at --x and --y of it, in percent. * A pin opens whatever its button opens: a popover with popovertarget, a tooltip with interestfor. * A pin is a small disc of ink with a white rim and a dark shade outside the rim, so it reads on any * picture in either theme. It may hold a number. A ring leaves it now and then, to say it can be pressed; * with reduced motion the ring rests. * Geometry: a 24px disc, and a 44px target on a touch screen. */@layer components.ui {  .hotspot {    position: relative;    display: block;    width: fit-content;    max-width: 100%;    min-width: 0;    margin: 0;  }  /* One pin: its middle stands on the point. */  .hotspot-pin {    --hotspot-size: 1.5rem;    position: absolute;    top: var(--y, 50%);    left: var(--x, 50%);    display: grid;    place-items: center;    width: var(--hotspot-size);    height: var(--hotspot-size);    margin: 0;    padding: 0;    border: 0;    border-radius: 999px;    corner-shape: round;    background: var(--color-surface-inverse);    color: var(--color-text-inverse);    box-shadow: 0 0 0 1.5px var(--color-on-image), 0 0 0 2px var(--color-on-image-shade), 0 2px 6px 1px var(--color-on-image-shade);    font: var(--font-weight-control) .6875rem/1 var(--font-family-sans);    font-feature-settings: inherit;    font-variant-numeric: tabular-nums;    /* A pin written as a link holds its number without the link's line. */    text-decoration: none;    translate: -50% -50%;    appearance: none;    cursor: pointer;    touch-action: manipulation;    user-select: none;    -webkit-user-select: none;    -webkit-tap-highlight-color: transparent;    transition: scale var(--duration-quick) var(--easing-glide);    /* The ring that leaves the pin. */    &::before {      content: '';      position: absolute;      inset: 0;      border-radius: inherit;      corner-shape: inherit;      box-shadow: 0 0 0 0 color-mix(in oklab, var(--color-on-image) 70%, transparent);      pointer-events: none;      animation: hotspot-ring 2.4s var(--easing-glide) infinite;    }    /* The target a finger needs, around the disc. */    &::after {      content: '';      position: absolute;      inset: 0;      @media (pointer: coarse) {        inset: calc((var(--hotspot-size) - 2.75rem) / 2);      }    }    /*     * Found: the ring that asks to be noticed rests while the pin is under the pointer or has focus. The pin in     * use stands above its neighbors, so its ring and its grown disc are never under another pin.     */    @media (hover: hover) {      &:hover {        z-index: 1;        scale: 1.12;      }      &:hover::before {        animation: none;      }    }    &:focus-visible::before {      animation: none;    }    /* While what it opens, right after it, is showing, the pin has been found: its ring rests and it stands above. */    &:has(+ :is(.popover, .tooltip):popover-open) {      z-index: 1;      &::before {        animation: none;      }    }    &:active {      scale: .94;      transition-duration: var(--duration-press);    }    &:focus-visible {      z-index: 1;      outline: 2px solid var(--color-on-image);      outline-offset: 3px;      box-shadow: 0 0 0 1.5px var(--color-on-image), 0 0 0 3px var(--color-focus), 0 0 0 7px var(--color-on-image-shade);    }    @media (prefers-reduced-motion: reduce) {      transition: none;      &::before {        animation: none;      }      &:hover, &:active {        scale: none;      }    }    @media (forced-colors: active) {      outline: 2px solid ButtonText;      outline-offset: -2px;      background: ButtonFace;      color: ButtonText;      &::before {        animation: none;      }      /* Keyboard focus is a ring of the highlight, as on a button. */      &:focus-visible {        outline-color: Highlight;      }    }  }}@keyframes hotspot-ring {  0%, 20% {    box-shadow: 0 0 0 0 color-mix(in oklab, var(--color-on-image) 70%, transparent);  }  70%, 100% {    box-shadow: 0 0 0 .75rem transparent;  }}