탐색

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>

#접근성

  • 모든 핀에는 가리키는 대상을 설명하는 접근 가능한 이름이 필요합니다. "핀 1" 대신 aria-label="The arm"처럼 지정하세요. 핀 안의 번호만으로는 이름을 대신할 수 없습니다.
  • 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;  }}