【第4回】HTML解説 アニメーションとトランジションで動きをつけよう【2025年最新版】
第3回までで、HTMLの構造とCSSのデザインを学びました。しかし、静止したWebページはどこか物足りなく感じませんか?ボタンをクリックしても反応がない、画像が突然現れる、スクロールしても何も変わらない...
今回はCSSアニメーションとトランジションを使って、Webページに「命」を吹き込む方法を学びます。難しいJavaScriptを使わなくても、CSSだけで驚くほど動きのあるインタラクティブなページが作れます!
この記事で学べること
- アニメーションとトランジションの違い
- ホバー時にボタンが浮き上がる効果の作り方
- ページ読み込み時のフェードインアニメーション
- ローディングスピナーの実装
- スムーズなページ内スクロール
- 実務で使える実践的なアニメーションパターン集
- パフォーマンスを考慮したアニメーション設計
所要時間: 約25分 難易度: ★★☆☆☆(初級〜中級)
前提知識: 第3回 CSSデザイン編を読んでいることを推奨します。
1. アニメーションとトランジションの違いを理解しよう
2つの動きの違い
CSSで動きをつける方法は主に2つあります。最初に違いを理解しましょう。
Transition(トランジション)= 「変化を滑らかにする」
特徴:
- ユーザーの操作(ホバー、クリック、フォーカスなど)で発動
- AからBへの状態変化を滑らかにする
- 簡単に実装できる
- 基本的な動きに最適
例: ボタンにマウスを乗せると色がゆっくり変わる
.button {
background-color: blue;
transition: background-color 0.3s; /* 0.3秒かけて変化 */
}
.button:hover {
background-color: red; /* マウスを乗せると赤に */
}
Animation(アニメーション)= 「自動で動く」
特徴:
- 自動で動き出す(ユーザーの操作不要)
- 複雑な動きができる(回転、拡大縮小、移動など)
- キーフレームで細かく制御
- ループ再生も可能
例: ページを開いた瞬間にロゴが回転
@keyframes rotate {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.logo {
animation: rotate 2s infinite; /* 2秒で1回転、無限ループ */
}
どちらを使えばいい?
| 使う場面 | 使うべき技術 |
|---|---|
| ボタンのホバー効果 | Transition |
| リンクの色変化 | Transition |
| ローディングアイコン | Animation |
| ページ読み込み時の登場演出 | Animation |
| スライドショー | Animation |
覚え方: 「ユーザーが何かしたら動く」→ Transition、「勝手に動く」→ Animation
2. Transitionの基礎:ホバーエフェクトを作ろう
基本の書き方
要素 {
transition: 何を 時間 動き方;
}
例:
.box {
background-color: blue;
transition: background-color 0.5s ease;
}
.box:hover {
background-color: red;
}
解説:
background-color= 背景色を変化させる0.5s= 0.5秒かけて変化ease= ゆっくり始まって、ゆっくり終わる
transitionで変化できる主なプロパティ
| プロパティ | 例 | 用途 |
|---|---|---|
background-color | 色が変わる | ホバー時の背景色 |
color | 文字色が変わる | リンクのホバー |
transform | 動く、回る、拡大 | ボタンが浮く |
opacity | 透明度が変わる | フェードイン/アウト |
width, height | サイズが変わる | 要素の伸縮 |
box-shadow | 影が変わる | 立体感の変化 |
実例1: ボタンが浮き上がる効果
これは最も人気のあるエフェクトです!
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>浮き上がるボタン</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #f5f5f5;
font-family: 'Hiragino Sans', sans-serif;
}
.floating-button {
padding: 16px 40px;
font-size: 18px;
font-weight: bold;
color: white;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border: none;
border-radius: 50px;
cursor: pointer;
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
/* トランジションを設定 */
transition: all 0.3s ease;
}
.floating-button:hover {
transform: translateY(-5px); /* 5px上に移動 */
box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6); /* 影を濃く */
}
.floating-button:active {
transform: translateY(-2px); /* クリック時は少し下がる */
}
</style>
</head>
<body>
<button class="floating-button">マウスを乗せてみて!</button>
</body>
</html>
ポイント解説:
transform: translateY(-5px)→ Y軸(縦方向)に-5px = 上に5px移動transition: all 0.3s ease→ すべてのプロパティを0.3秒で変化:active→ ボタンを押している間のスタイル
実例2: リンクの下線が伸びる効果
<style>
.animated-link {
position: relative;
color: #333;
text-decoration: none;
font-size: 20px;
font-weight: bold;
}
/* 下線を疑似要素で作る */
.animated-link::after {
content: "";
position: absolute;
bottom: -2px;
left: 0;
width: 0; /* 最初は幅0 */
height: 3px;
background: linear-gradient(90deg, #667eea, #764ba2);
transition: width 0.3s ease; /* 幅の変化を滑らかに */
}
.animated-link:hover::after {
width: 100%; /* ホバー時に全幅に */
}
</style>
<a href="#" class="animated-link">マウスを乗せると下線が伸びます</a>
技術解説:
::after= 疑似要素。要素の後ろに追加のコンテンツを挿入width: 0→width: 100%で左から右へ伸びるposition: absoluteで位置を自由に配置
実例3: 画像が拡大する効果
<style>
.image-container {
width: 300px;
height: 300px;
overflow: hidden; /* はみ出た部分を隠す */
border-radius: 12px;
}
.zoom-image {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.5s ease;
}
.image-container:hover .zoom-image {
transform: scale(1.1); /* 1.1倍に拡大 */
}
</style>
<div class="image-container">
<img src="https://via.placeholder.com/300" alt="画像" class="zoom-image">
</div>
使用例: 商品一覧ページの画像、ギャラリー、ポートフォリオサイト
3. イージング(動きの質感)を理解しよう
transitionの3番目のパラメータ「イージング」で、動きの質感が大きく変わります。
主なイージング関数
.element {
transition: all 0.3s ease; /* ゆっくり始まり、ゆっくり終わる */
transition: all 0.3s linear; /* 一定速度 */
transition: all 0.3s ease-in; /* ゆっくり始まる */
transition: all 0.3s ease-out; /* ゆっくり終わる */
transition: all 0.3s ease-in-out; /* 両方ゆっくり */
}
比較してみよう
<style>
.box {
width: 100px;
height: 100px;
background-color: #3498db;
margin: 20px;
color: white;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
}
.box:hover {
transform: translateX(200px); /* 右に200px移動 */
}
.linear { transition: transform 1s linear; }
.ease { transition: transform 1s ease; }
.ease-in { transition: transform 1s ease-in; }
.ease-out { transition: transform 1s ease-out; }
</style>
<div class="box linear">linear</div>
<div class="box ease">ease</div>
<div class="box ease-in">ease-in</div>
<div class="box ease-out">ease-out</div>
どれを使う?
- 迷ったら
ease- 最も自然な動き - 落下する動き →
ease-in - バウンドする動き →
ease-out - スムーズな移動 →
ease-in-out
カスタムイージング(cubic-bezier)
より細かく制御したい場合は、cubic-bezierを使います。
.custom-easing {
transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
/* バウンド効果 */
}
便利なツール: cubic-bezier.com でビジュアルに作成できます
4. Animationの基礎:自動で動かそう
キーフレームの書き方
アニメーションは「キーフレーム」で動きを定義します。
@keyframes アニメーション名 {
0% {
/* 開始時の状態 */
}
50% {
/* 中間の状態 */
}
100% {
/* 終了時の状態 */
}
}
.element {
animation: アニメーション名 時間 繰り返し;
}
実例1: フェードイン(徐々に現れる)
ページ読み込み時に要素がふわっと現れる、とても人気の効果です。
<style>
@keyframes fadeIn {
from {
opacity: 0; /* 透明 */
transform: translateY(20px); /* 20px下に */
}
to {
opacity: 1; /* 不透明 */
transform: translateY(0); /* 元の位置 */
}
}
.fade-in-element {
animation: fadeIn 0.8s ease-out;
}
/* 複数の要素を順番に表示 */
.fade-in-1 { animation: fadeIn 0.8s ease-out 0s; }
.fade-in-2 { animation: fadeIn 0.8s ease-out 0.2s; }
.fade-in-3 { animation: fadeIn 0.8s ease-out 0.4s; }
</style>
<div class="fade-in-1">最初に表示</div>
<div class="fade-in-2">次に表示</div>
<div class="fade-in-3">最後に表示</div>
解説:
0s,0.2s,0.4s= アニメーション開始までの遅延時間- 0.2秒ずつずらすことで、順番に表示される
実例2: ローディングスピナー
<style>
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.spinner {
width: 50px;
height: 50px;
border: 5px solid #f3f3f3;
border-top: 5px solid #3498db;
border-radius: 50%;
animation: spin 1s linear infinite;
}
</style>
<div class="spinner"></div>
パラメータ解説:
1s= 1秒で1回転linear= 一定速度(回転は一定が自然)infinite= 無限に繰り返す
実例3: パルス(脈打つ)効果
通知アイコンやCTAボタンに使えます。
<style>
@keyframes pulse {
0%, 100% {
transform: scale(1);
opacity: 1;
}
50% {
transform: scale(1.1);
opacity: 0.8;
}
}
.pulse-button {
padding: 15px 30px;
font-size: 18px;
background-color: #e74c3c;
color: white;
border: none;
border-radius: 50px;
cursor: pointer;
animation: pulse 2s ease-in-out infinite;
}
</style>
<button class="pulse-button">今すぐ購入!</button>
使用例: 限定セール、新着通知、重要なCTAボタン
実例4: バウンス(跳ねる)効果
<style>
@keyframes bounce {
0%, 20%, 50%, 80%, 100% {
transform: translateY(0);
}
40% {
transform: translateY(-30px);
}
60% {
transform: translateY(-15px);
}
}
.bounce-arrow {
display: inline-block;
font-size: 40px;
animation: bounce 2s infinite;
}
</style>
<div class="bounce-arrow">↓</div>
使用例: スクロール促進の矢印、注目を集めたい要素
5. アニメーションのプロパティを使いこなそう
animation の詳細設定
.element {
animation-name: fadeIn; /* アニメーション名 */
animation-duration: 1s; /* 再生時間 */
animation-timing-function: ease; /* イージング */
animation-delay: 0.5s; /* 開始遅延 */
animation-iteration-count: 3; /* 繰り返し回数(infiniteで無限) */
animation-direction: normal; /* 再生方向 */
animation-fill-mode: forwards; /* 終了後の状態 */
}
/* 短縮形 */
.element {
animation: fadeIn 1s ease 0.5s 3 normal forwards;
}
animation-fill-mode の使い分け
これは初心者が躓きやすいポイントです。
/* none(デフォルト)- アニメーション終了後、元に戻る */
.element-1 {
animation: fadeIn 1s ease none;
}
/* forwards - アニメーション終了後、最終状態を保持 */
.element-2 {
animation: fadeIn 1s ease forwards;
}
/* backwards - 開始前に最初のキーフレームを適用 */
.element-3 {
animation: fadeIn 1s ease 2s backwards;
}
/* both - forwardsとbackwards両方 */
.element-4 {
animation: fadeIn 1s ease 2s both;
}
実用例:
<style>
@keyframes slideIn {
from {
transform: translateX(-100%);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
.slide-in {
animation: slideIn 0.5s ease forwards;
/* forwardsで最終位置に留まる */
}
</style>
6. 実践:プロフェッショナルなアニメーションパターン集
パターン1: モーダルの登場・退場
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>モーダルアニメーション</title>
<style>
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.modal-content {
background: white;
padding: 40px;
border-radius: 12px;
max-width: 500px;
animation: slideUp 0.4s ease;
}
@keyframes slideUp {
from {
transform: translateY(50px);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
.close-button {
margin-top: 20px;
padding: 10px 20px;
background-color: #e74c3c;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
transition: background-color 0.3s;
}
.close-button:hover {
background-color: #c0392b;
}
</style>
</head>
<body>
<div class="modal-overlay">
<div class="modal-content">
<h2>ようこそ!</h2>
<p>このモーダルは滑らかにアニメーションします。</p>
<button class="close-button">閉じる</button>
</div>
</div>
</body>
</html>
パターン2: カードの登場アニメーション
<style>
@keyframes cardAppear {
from {
transform: scale(0.8);
opacity: 0;
}
to {
transform: scale(1);
opacity: 1;
}
}
.card {
background: white;
padding: 30px;
border-radius: 12px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
margin: 20px;
animation: cardAppear 0.5s ease;
}
/* 複数のカードを順番に表示 */
.card:nth-child(1) { animation-delay: 0s; }
.card:nth-child(2) { animation-delay: 0.1s; }
.card:nth-child(3) { animation-delay: 0.2s; }
.card:nth-child(4) { animation-delay: 0.3s; }
</style>
<div class="card">カード1</div>
<div class="card">カード2</div>
<div class="card">カード3</div>
<div class="card">カード4</div>
パターン3: テキストタイピング風アニメーション
<style>
@keyframes typing {
from { width: 0; }
to { width: 100%; }
}
@keyframes blink {
50% { border-color: transparent; }
}
.typing-text {
display: inline-block;
overflow: hidden;
white-space: nowrap;
border-right: 3px solid #333;
font-size: 24px;
font-weight: bold;
animation:
typing 3s steps(30) 1s forwards,
blink 0.5s step-end infinite;
}
</style>
<div class="typing-text">こんにちは、世界!ようこそ私のサイトへ。</div>
解説:
steps(30)= 30段階で変化(タイピングっぽい動き)1s= 1秒後に開始- カーソルの点滅は別のアニメーション
パターン4: プログレスバー
<style>
.progress-container {
width: 100%;
height: 30px;
background-color: #f0f0f0;
border-radius: 15px;
overflow: hidden;
}
@keyframes fillProgress {
from { width: 0%; }
to { width: 75%; }
}
.progress-bar {
height: 100%;
background: linear-gradient(90deg, #667eea, #764ba2);
animation: fillProgress 2s ease-out forwards;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
}
</style>
<div class="progress-container">
<div class="progress-bar">75%</div>
</div>
7. スムーズスクロールを実装しよう
CSSだけで実装する方法
html {
scroll-behavior: smooth;
}
たったこれだけ!ページ内リンクをクリックすると滑らかにスクロールします。
<style>
html {
scroll-behavior: smooth;
}
section {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
font-size: 48px;
}
nav {
position: fixed;
top: 20px;
left: 20px;
}
nav a {
display: block;
margin: 10px 0;
padding: 10px 20px;
background-color: white;
color: #333;
text-decoration: none;
border-radius: 6px;
transition: background-color 0.3s;
}
nav a:hover {
background-color: #3498db;
color: white;
}
</style>
<nav>
<a href="#section1">セクション1</a>
<a href="#section2">セクション2</a>
<a href="#section3">セクション3</a>
</nav>
<section id="section1" style="background: #e74c3c;">セクション1</section>
<section id="section2" style="background: #3498db;">セクション2</section>
<section id="section3" style="background: #2ecc71;">セクション3</section>
8. パフォーマンスを考慮したアニメーション
アニメーションが重くなる原因
すべてのCSSプロパティが同じようにアニメーションできるわけではありません。
❌ 重い(避けるべき):
.heavy {
transition: width 0.3s, height 0.3s, left 0.3s, top 0.3s;
/* レイアウトの再計算が発生 */
}
✅ 軽い(推奨):
.light {
transition: transform 0.3s, opacity 0.3s;
/* GPUで処理される */
}
高速なアニメーションの4つのプロパティ
この4つだけを使えば超高速:
transform- 移動、回転、拡大縮小opacity- 透明度filter- フィルター効果will-change- 変化の予告
.optimized-animation {
/* ✅ これは高速 */
transform: translateX(100px) scale(1.2) rotate(45deg);
opacity: 0.5;
/* ❌ これは重い */
width: 200px;
height: 200px;
left: 100px;
top: 50px;
}
will-changeで更に最適化
.smooth-animation {
will-change: transform, opacity;
/* ブラウザに「これから変化するよ」と予告 */
}
.smooth-animation:hover {
transform: scale(1.1);
opacity: 0.9;
}
注意: will-changeは使いすぎると逆効果。本当に必要な要素だけに使う。
9. レスポンシブアニメーション
モバイルではアニメーションを控えめに
スマートフォンはPCより処理能力が低いため、派手なアニメーションは避けましょう。
/* デスクトップ - 派手なアニメーション */
.animated-element {
animation: complexAnimation 2s ease infinite;
}
/* モバイル - シンプルに */
@media (max-width: 768px) {
.animated-element {
animation: simpleAnimation 1s ease;
/* 繰り返しを減らす、時間を短く */
}
}
/* 省電力モード対応 */
@media (prefers-reduced-motion: reduce) {
.animated-element {
animation: none;
/* アニメーションを無効化 */
}
}
prefers-reduced-motion: ユーザーが「アニメーションを減らす」設定にしている場合に対応
10. よくある質問(FAQ)
Q1. アニメーションが動きません。なぜ?
チェックリスト:
- ✅
@keyframesのスペルミスはないか - ✅ アニメーション名が正しく一致しているか
- ✅
animation-durationを設定したか(デフォルトは0秒) - ✅ ブラウザの開発者ツール(F12)でエラーを確認
/* ❌ よくある間違い */
@keyframes fadeIn { ... }
.element {
animation: fadein 1s; /* 大文字小文字が違う! */
}
/* ✅ 正しい */
@keyframes fadeIn { ... }
.element {
animation: fadeIn 1s;
}
Q2. アニメーションが一瞬で終わってしまいます
原因: animation-durationが短すぎるか、設定されていない
/* ❌ 時間が短すぎる */
.element {
animation: fadeIn 0.1s; /* 0.1秒は短すぎて見えない */
}
/* ✅ 適切な時間 */
.element {
animation: fadeIn 0.8s; /* 0.5〜1秒が見やすい */
}
Q3. アニメーション終了後、元に戻ってしまいます
解決法: animation-fill-mode: forwards を追加
/* ❌ 終了後に元に戻る */
.element {
animation: slideIn 1s ease;
}
/* ✅ 終了後も最終状態を保持 */
.element {
animation: slideIn 1s ease forwards;
}
Q4. 複数のアニメーションを同時に実行したい
方法1: カンマで区切る
.element {
animation:
fadeIn 1s ease,
slideUp 1s ease,
rotate 2s linear infinite;
}
方法2: 別々に定義
.element {
animation-name: fadeIn, slideUp;
animation-duration: 1s, 1.5s;
animation-timing-function: ease, ease-out;
}
Q5. トランジションとアニメーション、どちらが簡単ですか?
トランジションの方が簡単です!
/* トランジション - たった2行 */
.button {
transition: all 0.3s;
}
.button:hover {
background-color: red;
}
/* アニメーション - 複数行必要 */
@keyframes changeColor {
to { background-color: red; }
}
.button:hover {
animation: changeColor 0.3s forwards;
}
使い分け: ホバー効果などシンプルな変化 → トランジション、複雑な動き・自動再生 → アニメーション
11. 実践課題:自分で作ってみよう
課題1: 「今すぐ購入」ボタンを作る(初級)
要件:
- ホバー時に浮き上がる
- 背景色が変わる
- 影が濃くなる
- スムーズに変化する
ヒント:
.buy-button {
transition: all 0.3s ease;
}
.buy-button:hover {
transform: translateY(-3px);
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
課題2: ローディング画面を作る(中級)
要件:
- 円形のスピナーが回転
- 「読み込み中...」のテキストが点滅
- 中央に配置
課題3: スクロールで要素が順番に現れる(上級)
要件:
- 画面に入ったら要素がフェードイン
- 3つの要素が0.2秒ずつずれて表示
- 下から上にスライドしながら現れる
12. プロが使う高度なテクニック
テクニック1: パララックス効果(視差効果)
背景と前景が異なる速度で動く効果です。
<style>
.parallax-container {
height: 100vh;
overflow-y: auto;
perspective: 1px;
}
.parallax-layer {
position: absolute;
width: 100%;
height: 100vh;
}
.background {
transform: translateZ(-1px) scale(2);
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.foreground {
transform: translateZ(0);
display: flex;
justify-content: center;
align-items: center;
font-size: 48px;
color: white;
}
</style>
<div class="parallax-container">
<div class="parallax-layer background"></div>
<div class="parallax-layer foreground">
<h1>パララックス効果</h1>
</div>
</div>
テクニック2: モーフィング(形が変わる)
<style>
.morph-shape {
width: 200px;
height: 200px;
background: linear-gradient(135deg, #667eea, #764ba2);
transition: border-radius 0.5s ease;
margin: 50px;
}
.morph-shape:hover {
border-radius: 50%; /* 四角から円に */
}
</style>
<div class="morph-shape"></div>
テクニック3: 3D回転カード
<style>
.card-3d {
width: 300px;
height: 400px;
perspective: 1000px;
margin: 50px;
}
.card-inner {
width: 100%;
height: 100%;
position: relative;
transform-style: preserve-3d;
transition: transform 0.8s;
}
.card-3d:hover .card-inner {
transform: rotateY(180deg);
}
.card-front,
.card-back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
border-radius: 12px;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
font-weight: bold;
}
.card-front {
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
}
.card-back {
background: linear-gradient(135deg, #f093fb, #f5576c);
color: white;
transform: rotateY(180deg);
}
</style>
<div class="card-3d">
<div class="card-inner">
<div class="card-front">表面</div>
<div class="card-back">裏面</div>
</div>
</div>
使用例: 商品カード、プロフィールカード、ゲーム要素
テクニック4: テキストグリッチ効果
<style>
@keyframes glitch {
0%, 100% {
transform: translate(0);
}
20% {
transform: translate(-2px, 2px);
}
40% {
transform: translate(-2px, -2px);
}
60% {
transform: translate(2px, 2px);
}
80% {
transform: translate(2px, -2px);
}
}
.glitch-text {
font-size: 48px;
font-weight: bold;
position: relative;
color: white;
animation: glitch 0.3s infinite;
}
.glitch-text:before {
content: attr(data-text);
position: absolute;
left: 2px;
text-shadow: -2px 0 #ff00de;
animation: glitch 0.3s infinite reverse;
}
.glitch-text:after {
content: attr(data-text);
position: absolute;
left: -2px;
text-shadow: 2px 0 #00ffff;
animation: glitch 0.3s infinite;
}
</style>
<div class="glitch-text" data-text="GLITCH">GLITCH</div>
使用例: ゲームサイト、テクノロジー系サイト、特殊効果
13. アニメーションライブラリの活用
Animate.css - すぐに使えるアニメーション集
自分で作らなくても、既存のライブラリを使えば簡単です。
使い方:
<head>
<!-- CDNから読み込み -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css">
</head>
<body>
<!-- クラスを追加するだけ -->
<h1 class="animate__animated animate__bounceIn">
バウンドして登場!
</h1>
<div class="animate__animated animate__fadeInUp">
フェードインしながら上昇
</div>
<button class="animate__animated animate__pulse animate__infinite">
脈打つボタン
</button>
</body>
人気のアニメーション:
animate__fadeIn- フェードインanimate__bounceIn- バウンドして登場animate__zoomIn- ズームインanimate__slideInLeft- 左からスライドanimate__pulse- 脈打つ
AOS (Animate On Scroll) - スクロール連動アニメーション
スクロールすると要素が現れるアニメーション。
<head>
<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
</head>
<body>
<div data-aos="fade-up">スクロールでフェードイン</div>
<div data-aos="zoom-in" data-aos-delay="200">ズームイン</div>
<div data-aos="flip-left">回転して登場</div>
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
<script>
AOS.init();
</script>
</body>
メリット: JavaScriptの知識不要、HTMLに属性を追加するだけ
14. デバッグとトラブルシューティング
Chrome DevToolsでアニメーションをデバッグ
- F12で開発者ツールを開く
- 「...」→ More tools → Animations を選択
- アニメーションが可視化され、速度調整も可能
よくあるエラーと解決法
エラー1: アニメーションがカクカクする
原因: 重いプロパティをアニメーションしている
/* ❌ 重い */
@keyframes bad {
to {
width: 500px;
left: 100px;
}
}
/* ✅ 軽い */
@keyframes good {
to {
transform: translateX(100px) scale(1.2);
}
}
エラー2: アニメーションが途中で止まる
原因: animation-iteration-countが設定されていない
/* ❌ 1回で終わる */
.element {
animation: spin 2s;
}
/* ✅ 無限ループ */
.element {
animation: spin 2s infinite;
}
エラー3: モバイルで動作しない
原因: ベンダープレフィックスが必要な場合がある
.element {
-webkit-animation: fadeIn 1s;
animation: fadeIn 1s;
-webkit-transform: translateX(100px);
transform: translateX(100px);
}
15. パフォーマンスチェックリスト
✅ やるべきこと
transformとopacityを優先的に使う- アニメーションの数を最小限に
will-changeで事前通知(使いすぎ注意)- 不要なアニメーションは
prefers-reduced-motionで無効化 - 60fpsを維持(1フレーム16.67ms以内)
❌ 避けるべきこと
width、height、top、leftなどのレイアウトプロパティ- 同時に多数の要素をアニメーション
- 複雑な影や効果の連続アニメーション
- モバイルで重いアニメーション
パフォーマンス測定方法
// Chrome DevToolsのConsoleで実行
console.time('animation');
// アニメーション実行
setTimeout(() => {
console.timeEnd('animation');
}, 1000);
目標: 16ms以内(60fps維持)
16. アクセシビリティへの配慮
アニメーションを減らす設定への対応
一部のユーザーは、乗り物酔いや視覚過敏のためアニメーションを避けています。
/* 通常のアニメーション */
.animated {
animation: complexAnimation 2s ease infinite;
}
/* アニメーション削減設定の場合 */
@media (prefers-reduced-motion: reduce) {
.animated {
animation: none;
/* またはシンプルなフェードだけ */
transition: opacity 0.3s;
}
}
フォーカスインジケーターを隠さない
/* ❌ アクセシビリティを損なう */
button:focus {
outline: none; /* キーボード操作が困難に */
}
/* ✅ 見やすいフォーカススタイル */
button:focus {
outline: 3px solid #3498db;
outline-offset: 2px;
}
17. 最新トレンド:2025年のアニメーション
トレンド1: マイクロインタラクション
小さな、しかし心地よいアニメーション。
.like-button {
transition: transform 0.1s;
}
.like-button:active {
transform: scale(0.9); /* クリック時に少し縮む */
}
.like-button.liked {
animation: heartBeat 0.3s;
}
@keyframes heartBeat {
0%, 100% { transform: scale(1); }
25% { transform: scale(1.2); }
50% { transform: scale(1.1); }
}
トレンド2: ガラスモーフィズム
半透明でぼかし効果のある、ガラスのような質感。
.glass-card {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 16px;
border: 1px solid rgba(255, 255, 255, 0.2);
padding: 30px;
transition: backdrop-filter 0.3s;
}
.glass-card:hover {
backdrop-filter: blur(20px);
background: rgba(255, 255, 255, 0.15);
}
トレンド3: 流動的なグラデーション
動くグラデーションで生き生きとした印象。
@keyframes gradientShift {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
.flowing-gradient {
background: linear-gradient(
270deg,
#667eea, #764ba2, #f093fb, #667eea
);
background-size: 300% 300%;
animation: gradientShift 8s ease infinite;
}
トレンド4: スクロールスナップ
スクロール時にピタッと止まる気持ちいい効果。
.scroll-container {
scroll-snap-type: y mandatory;
overflow-y: scroll;
height: 100vh;
}
.scroll-section {
scroll-snap-align: start;
height: 100vh;
}
18. まとめ:アニメーションマスターへの道
この記事で学んだこと
✅ 基礎知識
- TransitionとAnimationの違い
- キーフレームの書き方
- イージング関数の使い分け
✅ 実践的なテクニック
- ホバーエフェクト(浮き上がる、拡大など)
- ローディングアニメーション
- フェードイン・スライドイン
- モーダルの登場・退場
✅ プロのテクニック
- パフォーマンス最適化
- 3D変形
- パララックス効果
- レスポンシブアニメーション
✅ 実務で重要なこと
- アクセシビリティへの配慮
- パフォーマンスチェック
- ブラウザ互換性
- デバッグ方法
学習の次のステップ
1. 毎日小さなアニメーションを作る
おすすめの練習:
- 月曜日: ボタンのホバーエフェクト
- 火曜日: ローディングスピナー
- 水曜日: カードのフリップ効果
- 木曜日: テキストアニメーション
- 金曜日: 総合演習
2. 好きなサイトを模写する
人気サイトのアニメーション:
- Apple.com - 滑らかなスクロールアニメーション
- Stripe.com - 洗練されたマイクロインタラクション
- Awwwards.com - 最先端のWeb技術
3. CodePenで公開する
作ったアニメーションをCodePenで公開し、他の人の作品も見てみましょう。
CodePenで探すキーワード:
- "CSS Animation"
- "Button Hover Effect"
- "Loading Spinner"
- "Card Animation"
4. アニメーションライブラリを研究
学ぶべきライブラリ:
- Animate.css - 基本のアニメーション集
- AOS - スクロール連動
- GSAP - 最強のJavaScriptアニメーション
- Framer Motion - React用(次のステップ)
重要な心構え
やりすぎ注意!
- アニメーションは「調味料」。多すぎると逆効果
- ユーザー体験を損なわない範囲で
- パフォーマンスを常に意識
- アクセシビリティを忘れずに
完璧を目指さない
- 最初はぎこちなくても大丈夫
- 失敗から学ぶことの方が多い
- 少しずつ改善していく
次回予告
第5回: JavaScript入門 - フォームに本当の動きをつけよう
次回は、いよいよJavaScriptです!CSSアニメーションと組み合わせて:
- ボタンクリックでアニメーション発動
- フォームのリアルタイム検証
- データの保存と取得
- APIとの連携
- 実際に動くお問い合わせフォームを完成
最も重要なこと: この記事を読むだけでは上達しません。今日から1日1つ、小さなアニメーションを作ってみてください。1ヶ月後には驚くほど成長しているはずです。
さあ、あなたのWebページに命を吹き込みましょう!

