ナビゲーション

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アクセシブルな名前を持つボタンに適用するピンです。前景色で塗りつぶした直径 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;  }}