# スクロールで現れる要素（scroll-driven）のCSSアニメーション実装

> スクロールに連動して要素がフェードインする演出を、JavaScriptなしのanimation-timeline: view()で実装します。

- カテゴリ: 出現・入場
- URL: https://www.css-dictionary.com/animations/scroll-reveal/

## HTML

```html
<div class="scroller">
  <p class="hint">↓ この枠内をスクロール</p>
  <div class="item">アイテム 1</div>
  <div class="item">アイテム 2</div>
  <div class="item">アイテム 3</div>
  <div class="item">アイテム 4</div>
  <div class="item">アイテム 5</div>
  <div class="item">アイテム 6</div>
</div>
```

## CSS

```css
.scroller {
  height: 230px;
  overflow-y: auto;
  border: 1px solid #e2d8c2;
  border-radius: 8px;
  padding: 12px;
  width: 240px;
}

.hint {
  color: #7d7159;
  font-size: 12px;
  margin: 0 0 60px;
}

.item {
  padding: 16px;
  margin-block: 16px;
  background: #fff;
  border: 1px solid #e2d8c2;
  border-radius: 8px;
  animation: reveal linear both;
  animation-timeline: view();
  animation-range: entry 0% entry 90%;
}

@keyframes reveal {
  from {
    opacity: 0;
    translate: 0 24px;
    scale: 0.96;
  }
}

@media (prefers-reduced-motion: reduce) {
  .item { animation: none; }
}
```

## 仕組みの解説

animation-timeline: view()は「要素がスクロールコンテナ内に見えている割合」をアニメーションの進行度にします。時間ではなくスクロール位置が進行度なので、ゆっくりスクロールすればゆっくり現れます。animation-rangeのentry 0%〜90%は「見え始めから9割見えるまで」の区間で再生する指定です。従来のIntersectionObserver+クラス付替えを完全に置き換えられます。

## 実装のポイント

Firefoxは2026年7月時点で未対応です。animationショートハンドの後にanimation-timelineを書かないとリセットされる点にも注意（AI生成コードの定番バグ）。

## 使っているプロパティ

- [animation-timeline](https://www.css-dictionary.com/property/animation-timeline.md)
- [animation](https://www.css-dictionary.com/property/animation.md)
- [keyframes](https://www.css-dictionary.com/property/keyframes.md)
- [overflow](https://www.css-dictionary.com/property/overflow.md)
- [opacity](https://www.css-dictionary.com/property/opacity.md)

