탐색

v2.1.0
구조

스크롤 등장 효과

스크롤로 화면에 들어올 때 서서히 나타나며 살짝 떠오르는 콘텐츠로, 스크롤 기반 애니메이션을 사용해 스크립트가 필요 없습니다.

이 페이지의 내용

스크롤 등장 효과는 콘텐츠가 스크롤을 따라 화면에 들어올 때 적용됩니다. 요소의 앞부분이 뷰포트 경계를 통과하는 동안 콘텐츠가 서서히 나타나면서 마지막 몇 픽셀만큼 위로 움직인 뒤 제자리에 멈춥니다. 클래스 하나와 스크롤 기반 애니메이션으로 구현합니다. 요소를 감시하거나 동적으로 클래스를 추가할 필요 없이 스크롤 위치가 애니메이션의 진행을 결정합니다.

스크롤 등장 효과

<div class="flex flex-col gap-md max-w(420) mx-auto">  <p class="m(0) fg-text-muted text-sm text-center py-xl">Scroll down</p>  <article class="card mt(240)">    <header class="card-header">      <h3 class="card-title">Native first</h3>      <p class="card-description">Every overlay is a dialog or a popover, opened without script.</p>    </header>  </article>  <article class="card reveal">    <header class="card-header">      <h3 class="card-title">One material</h3>      <p class="card-description">Surfaces step apart on a ladder of light, in both themes.</p>    </header>  </article>  <article class="card reveal">    <header class="card-header">      <h3 class="card-title">Contracts</h3>      <p class="card-description">Each stylesheet says what it promises in a file beside it.</p>    </header>  </article>  <article class="card reveal" style="--reveal-scale: .96">    <header class="card-header">      <h3 class="card-title">Yours to change</h3>      <p class="card-description">Tokens retune every component; the source is there to own.</p>    </header>  </article>  <p class="m(0) fg-text-muted text-sm text-center py-xl">The end</p></div>
<div className="flex flex-col gap-md max-w(420) mx-auto">  <p className="m(0) fg-text-muted text-sm text-center py-xl">Scroll down</p>  <article className="card mt(240)">    <header className="card-header">      <h3 className="card-title">Native first</h3>      <p className="card-description">        Every overlay is a dialog or a popover, opened without script.      </p>    </header>  </article>  <article className="card reveal">    <header className="card-header">      <h3 className="card-title">One material</h3>      <p className="card-description">Surfaces step apart on a ladder of light, in both themes.</p>    </header>  </article>  <article className="card reveal">    <header className="card-header">      <h3 className="card-title">Contracts</h3>      <p className="card-description">Each stylesheet says what it promises in a file beside it.</p>    </header>  </article>  <article className="card reveal" style={{ '--reveal-scale': '.96' } as React.CSSProperties}>    <header className="card-header">      <h3 className="card-title">Yours to change</h3>      <p className="card-description">Tokens retune every component; the source is there to own.</p>    </header>  </article>  <p className="m(0) fg-text-muted text-sm text-center py-xl">The end</p></div>
<div class="flex flex-col gap-md max-w(420) mx-auto">  <p class="m(0) fg-text-muted text-sm text-center py-xl">Scroll down</p>  <article class="card mt(240)">    <header class="card-header">      <h3 class="card-title">Native first</h3>      <p class="card-description">Every overlay is a dialog or a popover, opened without script.</p>    </header>  </article>  <article class="card reveal">    <header class="card-header">      <h3 class="card-title">One material</h3>      <p class="card-description">Surfaces step apart on a ladder of light, in both themes.</p>    </header>  </article>  <article class="card reveal">    <header class="card-header">      <h3 class="card-title">Contracts</h3>      <p class="card-description">Each stylesheet says what it promises in a file beside it.</p>    </header>  </article>  <article class="card reveal" style="--reveal-scale: .96">    <header class="card-header">      <h3 class="card-title">Yours to change</h3>      <p class="card-description">Tokens retune every component; the source is there to own.</p>    </header>  </article>  <p class="m(0) fg-text-muted text-sm text-center py-xl">The end</p></div>
<template>  <div class="flex flex-col gap-md max-w(420) mx-auto">    <p class="m(0) fg-text-muted text-sm text-center py-xl">Scroll down</p>    <article class="card mt(240)">      <header class="card-header">        <h3 class="card-title">Native first</h3>        <p class="card-description">          Every overlay is a dialog or a popover, opened without script.        </p>      </header>    </article>    <article class="card reveal">      <header class="card-header">        <h3 class="card-title">One material</h3>        <p class="card-description">Surfaces step apart on a ladder of light, in both themes.</p>      </header>    </article>    <article class="card reveal">      <header class="card-header">        <h3 class="card-title">Contracts</h3>        <p class="card-description">Each stylesheet says what it promises in a file beside it.</p>      </header>    </article>    <article class="card reveal" style="--reveal-scale: .96">      <header class="card-header">        <h3 class="card-title">Yours to change</h3>        <p class="card-description">Tokens retune every component; the source is there to own.</p>      </header>    </article>    <p class="m(0) fg-text-muted text-sm text-center py-xl">The end</p>  </div></template>
미리보기를 스크롤하면 카드가 화면에 들어올 때마다 등장합니다.

#동작 방식

애니메이션은 요소 자체의 뷰 타임라인인 animation-timeline: view()에서 요소가 스크롤 영역에 들어오는 구간에 실행됩니다. 스크롤 위치가 애니메이션의 진행을 결정하므로 다음 세 가지 동작이 따릅니다.

  • 페이지를 열었을 때 이미 화면에 보이는 요소는 전혀 움직이지 않습니다. 첫 프레임이 그려지기 전에 진입 구간이 끝나기 때문입니다.
  • 반대 방향으로 스크롤하면 애니메이션도 역재생됩니다. 별도로 초기화할 필요가 없습니다.
  • 지연 시간을 조정하거나 요소마다 시작 시점을 따로 지정할 필요가 없습니다. 요소가 화면에 들어오는 순서대로 등장합니다.

애니메이션은 요소가 화면에 들어오기 시작한 뒤 처음 12rem 안에 끝납니다. 이 진입 구간의 길이는 --reveal-range 값으로 조정할 수 있습니다. 따라서 높이가 큰 섹션도 화면 한 높이를 스크롤하는 내내 서서히 나타나지는 않습니다. 높이가 이 구간보다 작은 요소는 전체가 보이는 순간 등장이 끝나므로 페이지의 마지막 요소도 항상 완전히 나타납니다.

#효과 조정

세 가지 속성으로 효과를 조정할 수 있습니다. 요소 자체에 설정하거나 여러 요소의 공통 부모에 설정하세요.

  • --reveal-distance는 요소가 위로 이동하는 거리이며 기본값은 16px입니다. 이동 없이 서서히 나타나게 하려면 0을 설정하세요.
  • --reveal-scale은 요소가 등장하기 시작할 때의 크기입니다. .96은 이미지나 카드에 적합합니다. 텍스트의 크기는 바꾸지 마세요.
  • --reveal-range는 요소가 화면에 얼마나 들어왔을 때 등장 효과가 끝나는지 정합니다.

#사용 시점

긴 페이지에서 랜딩 페이지의 섹션, 카드 한 줄, 그림처럼 블록 전체에 등장 효과를 적용하세요. 효과는 꼭 필요한 곳에만 사용하세요. 모든 요소에 적용하면 스크롤할 때마다 무언가가 움직이고, 빠르게 스크롤하는 독자는 콘텐츠가 나타날 때까지 기다려야 합니다.

독자가 즉시 읽어야 하는 텍스트, 대화 상자나 메뉴 안의 요소, 로드 중에 크기가 바뀌는 콘텐츠에는 적용하지 마세요.

#스크롤 기반 애니메이션 미지원 환경

브라우저가 animation-timeline: view()를 지원하지 않거나 독자가 시스템에서 동작 줄이기를 설정하면 클래스에 따른 효과 없이 콘텐츠가 그대로 표시됩니다. 인쇄할 때도 마찬가지입니다. 불투명도는 애니메이션 안에서만 설정하므로 콘텐츠 표시는 애니메이션에 의존하지 않습니다.

#접근성

  • 콘텐츠는 처음부터 문서와 접근성 트리에 포함됩니다. 화면에 들어오는 동안에는 불투명도와 위치만 바뀝니다.
  • prefers-reduced-motion: reduce가 적용되면 불투명도와 위치가 모두 그대로 유지됩니다.
  • 이동 거리를 짧게 유지하세요. 큰 블록이 멀리 움직이면 뷰포트의 넓은 영역에서 움직임이 일어나 일부 독자가 화면을 보기 어려울 수 있습니다.

#클래스

클래스설명
reveal요소의 첫 부분이 뷰포트에 들어오는 동안 서서히 나타나며 16px 위로 이동한 뒤 그 자리에 머뭅니다.

#사용자 지정 속성

속성기본값설명
--reveal-distance1rem위로 이동하는 거리입니다. 페이드 효과만 적용하려면 0으로 설정하세요
--reveal-scale1나타나기 시작할 때의 배율입니다. 이미지의 경우 .96을 예로 들 수 있습니다.
--reveal-range12rem요소가 뷰포트에 들어온 것으로 판단하는 데 필요한 노출 높이입니다. 이 값보다 낮은 요소는 전체가 보이는 순간 들어온 것으로 판단합니다

#소스

@master/ui/components/reveal.css
/* * Reveal: content that arrives as it scrolls into view. * A scroll-driven animation on the element's own view timeline: it fades in and rises the last few pixels * while its first stretch crosses the edge of the viewport, and is at rest from then on. Nothing observes * it and no class is added: the position of the scroll is the clock, so scrolling back plays it backwards * and what is already in view when the page opens does not move at all. * Without scroll-driven animations, and for a reader who asks for less motion, the content is simply there. * Geometry: 16px of travel, finished within the first 12rem of the element entering. */@layer components.ui {  .reveal {    --reveal-distance: 1rem;    --reveal-scale: 1;    --reveal-range: 12rem;    @supports (animation-timeline: view()) {      @media (prefers-reduced-motion: no-preference) {        /* Longhands: tools that fold the timeline into the shorthand write a value no browser reads. */        animation-name: reveal-arrive;        animation-timing-function: var(--easing-glide);        animation-fill-mode: both;        animation-timeline: view();        /* An element shorter than the range has arrived once all of it is in view. */        animation-range: entry 0% entry min(100%, var(--reveal-range));        /*         * Focus scrolls a control only just into view, where the content is still arriving: what holds focus is         * shown whole at once, so a faded ring is never where the keys landed.         */        &:focus-within {          animation-name: none;        }      }    }    @media print {      animation: none;    }  }}@keyframes reveal-arrive {  from {    opacity: 0;    scale: var(--reveal-scale);    translate: 0 var(--reveal-distance);  }}