Scrollin とは
scroll-fadeIn などのクラスを付けておくだけで、要素がスクロールでビューポートに入ったタイミングで自動的にアニメーションする、スクロールトリガーアニメーションライブラリです。
特徴:
- Vanilla JS — jQuery不要
- IntersectionObserver API — スクロールイベントの監視ではなくネイティブAPIを使用。パフォーマンスが良い
- transition ベース — フェードイン等の一度きりのアニメーションは
CSS transitionで実装。コードがシンプルで、FireShot問題が発生しない [unscrollin]属性 — 特定のセクション内でアニメーションを無効化できる.delayed-*/.fasted-*/.slowed-*でタイミング調整可能
基本的な使い方
1. ファイルを読み込む
<link rel="stylesheet" href="scrollin.css">
<script src="scrollin.js"></script>2. アニメーションさせたい要素にクラスを付ける
<p class="scroll-fadeIn">
スクロールでフェードインします
</p>
<img class="scroll-blurInBottom" src="image.jpg" alt="" />これだけで、要素がビューポートに入った瞬間にアニメーションが実行されます。一度きりで、スクロールアウト後は再実行されません。
利用可能なエフェクト一覧
フェードイン系
| クラス名 | 効果 |
|---|---|
scroll-fadeIn | フェードイン |
scroll-fadeInBottom | 下からフェードイン |
scroll-fadeInTop | 上からフェードイン |
scroll-fadeInLeft | 左からフェードイン |
scroll-fadeInRight | 右からフェードイン |
ブラーイン系
| クラス名 | 効果 |
|---|---|
scroll-blurIn | ブラーイン |
scroll-blurInBottom | 下からブラーイン |
scroll-blurInTop | 上からブラーイン |
scroll-blurInLeft | 左からブラーイン |
scroll-blurInRight | 右からブラーイン |
scroll-blurFadeOut | ブラーオーバーレイがフェードアウト |
scroll-blurOutTop / Bottom / Left / Right | ブラーオーバーレイがスケールアウト |
背景色系(::before を使用)
| クラス名 | 効果 |
|---|---|
scroll-bgFadeIn | 背景色がフェードイン |
scroll-bgInBottom | 背景色が下からスライドイン |
scroll-bgInLeft | 背景色が左からスライドイン |
scroll-bgOpenIn | 背景色が中央から広がる |
移動・スケール系
| クラス名 | 効果 |
|---|---|
scroll-moveInBottom | 下から微動してイン |
scroll-moveInTop / Left / Right | 各方向から微動してイン |
scroll-growIn | 拡大しながらイン |
scroll-growOut | 拡大しながらフェードアウト |
scroll-shrinkIn | 縮小しながらイン |
scroll-shrinkOut | 縮小しながらフェードアウト |
クリップイン系
| クラス名 | 効果 |
|---|---|
scroll-clipInBottom | 下からクリップイン |
scroll-clipInLeft / Right | 横からクリップイン |
scroll-clipInBottomLeft | 左下から菱形クリップイン |
scroll-clipInBottomRight | 右下から菱形クリップイン |
ワイプイン系
| クラス名 | 効果 |
|---|---|
scroll-wipeInCentral | 円形に広がってイン |
scroll-wipeInBottom | 下からワイプイン |
scroll-wipeInTop / Left / Right | 各方向からワイプイン |
幕系(::after を使用)
| クラス名 | 効果 |
|---|---|
scroll-coatInBottomOut | 幕が下から上がり、消えながら要素が現れる |
scroll-coatInLeftOut / RightOut | 幕が横から入り、消えながら要素が現れる |
scroll-coatInBottomLeftOut | 左下から斜めに幕が入り、消えながら要素が現れる |
scroll-coatFadeOut | 暗幕がフェードアウトして要素が現れる |
scroll-coatOutTop / Bottom / Left / Right | 暗幕が各方向へスケールアウト |
グラデーションマスク系
| クラス名 | 効果 |
|---|---|
scroll-mirageInBottom | 下からグラデーションマスクで表示 |
scroll-mirageInTop / Right / Left | 各方向からグラデーションマスクで表示 |
フリップイン系(3D)
| クラス名 | 効果 |
|---|---|
scroll-flipInXUp | X軸上向きフリップ |
scroll-flipInXDown | X軸下向きフリップ |
scroll-flipInYFore | Y軸前向きフリップ |
scroll-flipInYBack | Y軸後向きフリップ |
ループ系(animation-iteration-count: infinite)
| クラス名 | 効果 |
|---|---|
scroll-rotationDext | 時計回りに回転(画面内のみ再生) |
scroll-rotationLevo | 反時計回りに回転 |
scroll-looptationToFore | マーキー(左方向) |
scroll-looptationToBack | マーキー(右方向) |
scroll-looptationToUp | マーキー(上方向) |
scroll-looptationToDown | マーキー(下方向) |
特殊系
| クラス名 | 効果 |
|---|---|
scroll-chartation | 円グラフのパスアニメーション |
scroll-countation | 数値カウントアップ(data-count 属性で目標値を指定) |
タイミング調整クラス
ディレイ(.delayed-*)
アニメーションの開始を遅らせます。
<!-- 0.5秒遅れてフェードイン -->
<p class="scroll-fadeIn delayed-2">テキスト</p>| クラス | 遅延 |
|---|---|
delayed-0 | 0s |
delayed-1 | 0.25s |
delayed-2 | 0.5s |
delayed-3 | 0.75s |
delayed-4 | 1s |
delayed-5 | 1.25s |
delayed-6 | 1.5s |
速度調整(.fasted-* / .slowed-*)
<!-- ゆっくり(3秒)フェードイン -->
<p class="scroll-fadeIn slowed-3">テキスト</p>
<!-- 速く(0.5秒)フェードイン -->
<p class="scroll-blurIn fasted-2">テキスト</p>fasted-1(0.75s)〜 fasted-3(0.25s)、slowed-1(1.5s)〜 slowed-180(180s)が利用可能。
アニメーションを無効化する([unscrollin])
祖先要素に unscrollin 属性を付けると、その配下のアニメーションを無効化できます。
<!-- このセクション内のアニメーションはすべて無効 -->
<section unscrollin>
<p class="scroll-fadeIn">アニメーションせず即表示される</p>
</section>プリント用ページや、アクセシビリティ対応が必要な箇所に使います。
カウントアップ(scroll-countation)
数値をカウントアップするアニメーションです。
<span class="scroll-countation" data-count="1,234">1,234</span>
<span class="scroll-countation slowed-2" data-count="98.6%">98.6%</span>
<span class="scroll-countation" data-count="007">007</span>data-count 属性に目標値を書くと、スクロール時に0から数値がカウントアップされます。プレフィックス・サフィックス・小数点・ゼロパディングも自動判定します。
円グラフアニメーション(scroll-chartation)
SVGの stroke-dasharray を使って、円グラフが描かれるアニメーションです。
<div class="chart-donut scroll-chartation" data-percent="75">
<div class="chart-wrapper">
<svg viewBox="0 0 200 200">
<circle r="80" cx="100" cy="100" />
<circle id="thumb1" class="chartbar-thumb" r="80" cx="100" cy="100" />
</svg>
<div class="chart-central">
<p><b>75</b><small>%</small></p>
</div>
</div>
</div>data-percent に0〜100の数値を指定すると、その割合まで円弧が描かれます。
実装の仕組み
- ページ読み込み時に
scroll-*クラスを持つ要素を検出し、IntersectionObserverに登録 - 要素がビューポートに入ると
is-scloadedクラスが付与される transitionベースのエフェクトは、is-scloadedで最終状態のCSSが適用されてアニメーションが発火- ループ系以外は一度きりで監視が解除される(メモリ効率化)
- ループ系(rotation / looptation)は画面外に出ると
animation-play-state: pausedで一時停止
prefers-reduced-motion 対応
@media (prefers-reduced-motion: reduce) が設定されている場合、主要なアニメーション・トランジションが無効になり、要素は最終表示状態で即時表示されます。
対応ブラウザ
IntersectionObserver API に対応したモダンブラウザで動作します。
- Chrome 51+
- Firefox 55+
- Safari 12.1+
- Edge 15+

