
サイドメニューの表示アニメーションを実装したい……



モバイル対応のスライドメニューを作りたい……
今回はこのようなお悩みをお持ちの方へ向けて
Web制作において人気の高いアニメーション効果
サイドメニュー表示アニメーション
をご紹介します。
- スライドイン(左右からのスライド表示)
- プッシュ(メインコンテンツを押し出す表示)
- オーバーレイ(上に重ねる表示)
- ブラー(背景のぼかし効果)
- ダークオーバーレイ(暗いオーバーレイ)



特にモバイルサイトやタブレット対応には、サイドメニュー表示アニメーションが非常に効果的です。この記事のコードをご活用いただきWeb制作の効率化に繋がれば何よりです。
なお、今回ご紹介するアニメーションはCSSとJavaScriptを組み合わせて実装するので、スムーズで魅力的なインタラクションを実現できます。
あわせて読みたい
サイドメニュー表示アニメーションとは
サイドメニュー表示アニメーションは、メニューが画面の左右からスライドして表示される視覚的な効果です。ユーザーの注目を集め、スムーズなインタラクションを提供するための手法です。
効果的な使用場面
適している場面
- モバイルサイト
- タブレット対応
- サイドバーナビゲーション
- 設定メニュー
- カテゴリメニュー
避けるべき場面
- デスクトップのメインナビゲーション
- 重要な情報の表示
- アクセシビリティを重視する場面
- 過度に使用した場合
実装方法の比較
アニメーション | 難易度 | 視覚的インパクト | パフォーマンス | ブラウザ対応 |
---|---|---|---|---|
スライドイン | ⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
プッシュ | ⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ |
オーバーレイ | ⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
ブラー | ⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ |
ダークオーバーレイ | ⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
スライドイン
① デモ
See the Pen サイドメニュースライドイン by ケケンタ (@lgshifbg-the-looper) on CodePen.
- 左右からのスライド表示
- 自然な動き
- 視覚的インパクト中
- 直感的な印象
② HTML
<div class="page-container">
<header class="header">
<button class="menu-toggle" id="menuToggle">
<span class="hamburger"></span>
</button>
<h1>サイトタイトル</h1>
</header>
<nav class="side-menu slide-in" id="sideMenu">
<div class="menu-header">
<h2>メニュー</h2>
<button class="close-btn" id="closeMenu">×</button>
</div>
<ul class="menu-list">
<li><a href="#">ホーム</a></li>
<li><a href="#">サービス</a></li>
<li><a href="#">会社概要</a></li>
<li><a href="#">お問い合わせ</a></li>
</ul>
</nav>
<main class="main-content">
<h2>メインコンテンツ</h2>
<p>ここにメインコンテンツが入ります。</p>
</main>
</div>
③ CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
overflow-x: hidden;
}
.page-container {
position: relative;
min-height: 100vh;
}
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 60px;
background: #667eea;
color: white;
display: flex;
align-items: center;
padding: 0 20px;
z-index: 100;
}
.menu-toggle {
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
margin-right: 20px;
}
.hamburger {
display: block;
width: 25px;
height: 3px;
background: white;
position: relative;
transition: all 0.3s ease;
}
.hamburger::before,
.hamburger::after {
content: '';
position: absolute;
width: 25px;
height: 3px;
background: white;
transition: all 0.3s ease;
}
.hamburger::before {
top: -8px;
}
.hamburger::after {
bottom: -8px;
}
.menu-toggle.active .hamburger {
background: transparent;
}
.menu-toggle.active .hamburger::before {
transform: rotate(45deg);
top: 0;
}
.menu-toggle.active .hamburger::after {
transform: rotate(-45deg);
bottom: 0;
}
.side-menu {
position: fixed;
top: 0;
left: -300px;
width: 300px;
height: 100vh;
background: white;
box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
z-index: 200;
transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
overflow-y: auto;
}
.side-menu.active {
left: 0;
}
.menu-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
border-bottom: 1px solid #e1e5e9;
background: #f8f9fa;
}
.menu-header h2 {
color: #333;
font-size: 18px;
}
.close-btn {
background: none;
border: none;
font-size: 24px;
color: #666;
cursor: pointer;
padding: 5px;
}
.close-btn:hover {
color: #333;
}
.menu-list {
list-style: none;
padding: 0;
}
.menu-list li {
border-bottom: 1px solid #f0f0f0;
}
.menu-list a {
display: block;
padding: 15px 20px;
color: #333;
text-decoration: none;
transition: background-color 0.2s ease;
}
.menu-list a:hover {
background: #f8f9fa;
color: #667eea;
}
.main-content {
margin-top: 60px;
padding: 20px;
}
/* メニューが開いている時の背景オーバーレイ */
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 150;
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
}
.overlay.active {
opacity: 1;
visibility: visible;
}
④ JavaScript
document.addEventListener('DOMContentLoaded', function() {
const menuToggle = document.getElementById('menuToggle');
const sideMenu = document.getElementById('sideMenu');
const closeMenu = document.getElementById('closeMenu');
const overlay = document.querySelector('.overlay');
// メニューを開く
menuToggle.addEventListener('click', function() {
sideMenu.classList.add('active');
overlay.classList.add('active');
menuToggle.classList.add('active');
});
// メニューを閉じる
function closeSideMenu() {
sideMenu.classList.remove('active');
overlay.classList.remove('active');
menuToggle.classList.remove('active');
}
// 閉じるボタンでメニューを閉じる
closeMenu.addEventListener('click', closeSideMenu);
// オーバーレイクリックでメニューを閉じる
overlay.addEventListener('click', closeSideMenu);
// ESCキーでメニューを閉じる
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && sideMenu.classList.contains('active')) {
closeSideMenu();
}
});
});
⑤ カスタマイズ例
/* スライド方向の変更(右から) */
.side-menu {
left: auto;
right: -300px;
}
.side-menu.active {
right: 0;
}
/* スライド速度の変更 */
.side-menu {
transition: left 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
/* メニュー幅の変更 */
.side-menu {
width: 250px;
left: -250px;
}
プッシュ
① デモ
See the Pen サイドメニュープッシュ by ケケンタ (@lgshifbg-the-looper) on CodePen.
- メインコンテンツを押し出す表示
- 動的な効果
- 視覚的インパクト大
- モダンな印象
② HTML
<div class="page-container">
<header class="header">
<button class="menu-toggle" id="menuToggle">
<span class="hamburger"></span>
</button>
<h1>サイトタイトル</h1>
</header>
<nav class="side-menu push" id="sideMenu">
<div class="menu-header">
<h2>メニュー</h2>
<button class="close-btn" id="closeMenu">×</button>
</div>
<ul class="menu-list">
<li><a href="#">ホーム</a></li>
<li><a href="#">サービス</a></li>
<li><a href="#">会社概要</a></li>
<li><a href="#">お問い合わせ</a></li>
</ul>
</nav>
<main class="main-content push-content" id="mainContent">
<h2>メインコンテンツ</h2>
<p>ここにメインコンテンツが入ります。</p>
</main>
</div>
③ CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
overflow-x: hidden;
}
.page-container {
position: relative;
min-height: 100vh;
}
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 60px;
background: #667eea;
color: white;
display: flex;
align-items: center;
padding: 0 20px;
z-index: 100;
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.menu-toggle {
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
margin-right: 20px;
}
.hamburger {
display: block;
width: 25px;
height: 3px;
background: white;
position: relative;
transition: all 0.3s ease;
}
.hamburger::before,
.hamburger::after {
content: '';
position: absolute;
width: 25px;
height: 3px;
background: white;
transition: all 0.3s ease;
}
.hamburger::before {
top: -8px;
}
.hamburger::after {
bottom: -8px;
}
.menu-toggle.active .hamburger {
background: transparent;
}
.menu-toggle.active .hamburger::before {
transform: rotate(45deg);
top: 0;
}
.menu-toggle.active .hamburger::after {
transform: rotate(-45deg);
bottom: 0;
}
.side-menu {
position: fixed;
top: 0;
left: -300px;
width: 300px;
height: 100vh;
background: white;
box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
z-index: 200;
transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
overflow-y: auto;
}
.side-menu.active {
left: 0;
}
.menu-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
border-bottom: 1px solid #e1e5e9;
background: #f8f9fa;
}
.menu-header h2 {
color: #333;
font-size: 18px;
}
.close-btn {
background: none;
border: none;
font-size: 24px;
color: #666;
cursor: pointer;
padding: 5px;
}
.close-btn:hover {
color: #333;
}
.menu-list {
list-style: none;
padding: 0;
}
.menu-list li {
border-bottom: 1px solid #f0f0f0;
}
.menu-list a {
display: block;
padding: 15px 20px;
color: #333;
text-decoration: none;
transition: background-color 0.2s ease;
}
.menu-list a:hover {
background: #f8f9fa;
color: #667eea;
}
.main-content {
margin-top: 60px;
padding: 20px;
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.main-content.push-active {
transform: translateX(300px);
}
.header.push-active {
transform: translateX(300px);
}
④ JavaScript
document.addEventListener('DOMContentLoaded', function() {
const menuToggle = document.getElementById('menuToggle');
const sideMenu = document.getElementById('sideMenu');
const closeMenu = document.getElementById('closeMenu');
const mainContent = document.getElementById('mainContent');
const header = document.querySelector('.header');
// メニューを開く
menuToggle.addEventListener('click', function() {
sideMenu.classList.add('active');
mainContent.classList.add('push-active');
header.classList.add('push-active');
menuToggle.classList.add('active');
});
// メニューを閉じる
function closeSideMenu() {
sideMenu.classList.remove('active');
mainContent.classList.remove('push-active');
header.classList.remove('push-active');
menuToggle.classList.remove('active');
}
// 閉じるボタンでメニューを閉じる
closeMenu.addEventListener('click', closeSideMenu);
// ESCキーでメニューを閉じる
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && sideMenu.classList.contains('active')) {
closeSideMenu();
}
});
});
⑤ カスタマイズ例
/* プッシュ距離の変更 */
.main-content.push-active {
transform: translateX(250px);
}
.header.push-active {
transform: translateX(250px);
}
/* プッシュ速度の変更 */
.main-content {
transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.header {
transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
オーバーレイ
① デモ
See the Pen サイドメニューオーバーレイ by ケケンタ (@lgshifbg-the-looper) on CodePen.
- 上に重ねる表示
- シンプルな効果
- 視覚的インパクト小
- 軽量な印象
② HTML
<div class="page-container">
<header class="header">
<button class="menu-toggle" id="menuToggle">
<span class="hamburger"></span>
</button>
<h1>サイトタイトル</h1>
</header>
<nav class="side-menu overlay-menu" id="sideMenu">
<div class="menu-header">
<h2>メニュー</h2>
<button class="close-btn" id="closeMenu">×</button>
</div>
<ul class="menu-list">
<li><a href="#">ホーム</a></li>
<li><a href="#">サービス</a></li>
<li><a href="#">会社概要</a></li>
<li><a href="#">お問い合わせ</a></li>
</ul>
</nav>
<div class="overlay" id="overlay"></div>
<main class="main-content">
<h2>メインコンテンツ</h2>
<p>ここにメインコンテンツが入ります。</p>
</main>
</div>
③ CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
}
.page-container {
position: relative;
min-height: 100vh;
}
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 60px;
background: #667eea;
color: white;
display: flex;
align-items: center;
padding: 0 20px;
z-index: 100;
}
.menu-toggle {
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
margin-right: 20px;
}
.hamburger {
display: block;
width: 25px;
height: 3px;
background: white;
position: relative;
transition: all 0.3s ease;
}
.hamburger::before,
.hamburger::after {
content: '';
position: absolute;
width: 25px;
height: 3px;
background: white;
transition: all 0.3s ease;
}
.hamburger::before {
top: -8px;
}
.hamburger::after {
bottom: -8px;
}
.menu-toggle.active .hamburger {
background: transparent;
}
.menu-toggle.active .hamburger::before {
transform: rotate(45deg);
top: 0;
}
.menu-toggle.active .hamburger::after {
transform: rotate(-45deg);
bottom: 0;
}
.side-menu {
position: fixed;
top: 0;
left: 0;
width: 300px;
height: 100vh;
background: white;
box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
z-index: 200;
transform: translateX(-100%);
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
overflow-y: auto;
}
.side-menu.active {
transform: translateX(0);
}
.menu-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
border-bottom: 1px solid #e1e5e9;
background: #f8f9fa;
}
.menu-header h2 {
color: #333;
font-size: 18px;
}
.close-btn {
background: none;
border: none;
font-size: 24px;
color: #666;
cursor: pointer;
padding: 5px;
}
.close-btn:hover {
color: #333;
}
.menu-list {
list-style: none;
padding: 0;
}
.menu-list li {
border-bottom: 1px solid #f0f0f0;
}
.menu-list a {
display: block;
padding: 15px 20px;
color: #333;
text-decoration: none;
transition: background-color 0.2s ease;
}
.menu-list a:hover {
background: #f8f9fa;
color: #667eea;
}
.main-content {
margin-top: 60px;
padding: 20px;
}
/* 背景オーバーレイ */
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 150;
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
}
.overlay.active {
opacity: 1;
visibility: visible;
}
④ JavaScript
document.addEventListener('DOMContentLoaded', function() {
const menuToggle = document.getElementById('menuToggle');
const sideMenu = document.getElementById('sideMenu');
const closeMenu = document.getElementById('closeMenu');
const overlay = document.getElementById('overlay');
// メニューを開く
menuToggle.addEventListener('click', function() {
sideMenu.classList.add('active');
overlay.classList.add('active');
menuToggle.classList.add('active');
});
// メニューを閉じる
function closeSideMenu() {
sideMenu.classList.remove('active');
overlay.classList.remove('active');
menuToggle.classList.remove('active');
}
// 閉じるボタンでメニューを閉じる
closeMenu.addEventListener('click', closeSideMenu);
// オーバーレイクリックでメニューを閉じる
overlay.addEventListener('click', closeSideMenu);
// ESCキーでメニューを閉じる
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && sideMenu.classList.contains('active')) {
closeSideMenu();
}
});
});
⑤ カスタマイズ例
/* オーバーレイ方向の変更(右から) */
.side-menu {
left: auto;
right: 0;
transform: translateX(100%);
}
/* オーバーレイ速度の変更 */
.side-menu {
transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
/* メニュー幅の変更 */
.side-menu {
width: 250px;
}
/* オーバーレイ色の変更 */
.overlay {
background: rgba(0, 0, 0, 0.7);
}
/* オーバーレイ速度の変更 */
.overlay {
transition: all 0.5s ease;
}
ブラー
① デモ
See the Pen サイドメニューブラー by ケケンタ (@lgshifbg-the-looper) on CodePen.
- 背景のぼかし効果
- モダンな効果
- 視覚的インパクト大
- 高級感のある印象
② HTML
<div class="page-container">
<header class="header">
<button class="menu-toggle" id="menuToggle">
<span class="hamburger"></span>
</button>
<h1>サイトタイトル</h1>
</header>
<nav class="side-menu blur-menu" id="sideMenu">
<div class="menu-header">
<h2>メニュー</h2>
<button class="close-btn" id="closeMenu">×</button>
</div>
<ul class="menu-list">
<li><a href="#">ホーム</a></li>
<li><a href="#">サービス</a></li>
<li><a href="#">会社概要</a></li>
<li><a href="#">お問い合わせ</a></li>
</ul>
</nav>
<main class="main-content blur-content" id="mainContent">
<h2>メインコンテンツ</h2>
<p>ここにメインコンテンツが入ります。</p>
</main>
</div>
③ CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
overflow-x: hidden;
}
.page-container {
position: relative;
min-height: 100vh;
}
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 60px;
background: #667eea;
color: white;
display: flex;
align-items: center;
padding: 0 20px;
z-index: 100;
transition: filter 0.3s ease;
}
.menu-toggle {
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
margin-right: 20px;
}
.hamburger {
display: block;
width: 25px;
height: 3px;
background: white;
position: relative;
transition: all 0.3s ease;
}
.hamburger::before,
.hamburger::after {
content: '';
position: absolute;
width: 25px;
height: 3px;
background: white;
transition: all 0.3s ease;
}
.hamburger::before {
top: -8px;
}
.hamburger::after {
bottom: -8px;
}
.menu-toggle.active .hamburger {
background: transparent;
}
.menu-toggle.active .hamburger::before {
transform: rotate(45deg);
top: 0;
}
.menu-toggle.active .hamburger::after {
transform: rotate(-45deg);
bottom: 0;
}
.side-menu {
position: fixed;
top: 0;
left: -300px;
width: 300px;
height: 100vh;
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
z-index: 200;
transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
overflow-y: auto;
}
.side-menu.active {
left: 0;
}
.menu-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
border-bottom: 1px solid rgba(225, 229, 233, 0.5);
background: rgba(248, 249, 250, 0.8);
}
.menu-header h2 {
color: #333;
font-size: 18px;
}
.close-btn {
background: none;
border: none;
font-size: 24px;
color: #666;
cursor: pointer;
padding: 5px;
}
.close-btn:hover {
color: #333;
}
.menu-list {
list-style: none;
padding: 0;
}
.menu-list li {
border-bottom: 1px solid rgba(240, 240, 240, 0.5);
}
.menu-list a {
display: block;
padding: 15px 20px;
color: #333;
text-decoration: none;
transition: background-color 0.2s ease;
}
.menu-list a:hover {
background: rgba(248, 249, 250, 0.8);
color: #667eea;
}
.main-content {
margin-top: 60px;
padding: 20px;
transition: filter 0.3s ease;
}
.main-content.blur-active {
filter: blur(5px);
}
.header.blur-active {
filter: blur(5px);
}
④ JavaScript
document.addEventListener('DOMContentLoaded', function() {
const menuToggle = document.getElementById('menuToggle');
const sideMenu = document.getElementById('sideMenu');
const closeMenu = document.getElementById('closeMenu');
const mainContent = document.getElementById('mainContent');
const header = document.querySelector('.header');
// メニューを開く
menuToggle.addEventListener('click', function() {
sideMenu.classList.add('active');
mainContent.classList.add('blur-active');
header.classList.add('blur-active');
menuToggle.classList.add('active');
});
// メニューを閉じる
function closeSideMenu() {
sideMenu.classList.remove('active');
mainContent.classList.remove('blur-active');
header.classList.remove('blur-active');
menuToggle.classList.remove('active');
}
// 閉じるボタンでメニューを閉じる
closeMenu.addEventListener('click', closeSideMenu);
// ESCキーでメニューを閉じる
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && sideMenu.classList.contains('active')) {
closeSideMenu();
}
});
});
⑤ カスタマイズ例
/* ブラー強度の変更 */
.main-content.blur-active {
filter: blur(10px);
}
.header.blur-active {
filter: blur(10px);
}
/* メニューの透明度変更 */
.side-menu {
background: rgba(255, 255, 255, 0.9);
}
/* ブラー速度の変更 */
.main-content {
transition: filter 0.5s ease;
}
.header {
transition: filter 0.5s ease;
}
ダークオーバーレイ
① デモ
See the Pen サイドメニューダークオーバーレイ by ケケンタ (@lgshifbg-the-looper) on CodePen.
- 濃い暗いオーバーレイ
- 劇的な効果
- 視覚的インパクト大
- 高級感のある印象
② HTML
<div class="page-container">
<header class="header">
<button class="menu-toggle" id="menuToggle">
<span class="hamburger"></span>
</button>
<h1>サイトタイトル</h1>
</header>
<nav class="side-menu dark-overlay-menu" id="sideMenu">
<div class="menu-header">
<h2>メニュー</h2>
<button class="close-btn" id="closeMenu">×</button>
</div>
<ul class="menu-list">
<li><a href="#">ホーム</a></li>
<li><a href="#">サービス</a></li>
<li><a href="#">会社概要</a></li>
<li><a href="#">お問い合わせ</a></li>
</ul>
</nav>
<div class="dark-overlay" id="darkOverlay"></div>
<main class="main-content">
<h2>メインコンテンツ</h2>
<p>ここにメインコンテンツが入ります。</p>
</main>
</div>
③ CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
overflow-x: hidden;
}
.page-container {
position: relative;
min-height: 100vh;
}
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 60px;
background: #667eea;
color: white;
display: flex;
align-items: center;
padding: 0 20px;
z-index: 100;
}
.menu-toggle {
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
margin-right: 20px;
}
.hamburger {
display: block;
width: 25px;
height: 3px;
background: white;
position: relative;
transition: all 0.3s ease;
}
.hamburger::before,
.hamburger::after {
content: '';
position: absolute;
width: 25px;
height: 3px;
background: white;
transition: all 0.3s ease;
}
.hamburger::before {
top: -8px;
}
.hamburger::after {
bottom: -8px;
}
.menu-toggle.active .hamburger {
background: transparent;
}
.menu-toggle.active .hamburger::before {
transform: rotate(45deg);
top: 0;
}
.menu-toggle.active .hamburger::after {
transform: rotate(-45deg);
bottom: 0;
}
.side-menu {
position: fixed;
top: 0;
left: -300px;
width: 300px;
height: 100vh;
background: white;
box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
z-index: 200;
transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
overflow-y: auto;
}
.side-menu.active {
left: 0;
}
.menu-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
border-bottom: 1px solid #e1e5e9;
background: #f8f9fa;
}
.menu-header h2 {
color: #333;
font-size: 18px;
}
.close-btn {
background: none;
border: none;
font-size: 24px;
color: #666;
cursor: pointer;
padding: 5px;
}
.close-btn:hover {
color: #333;
}
.menu-list {
list-style: none;
padding: 0;
}
.menu-list li {
border-bottom: 1px solid #f0f0f0;
}
.menu-list a {
display: block;
padding: 15px 20px;
color: #333;
text-decoration: none;
transition: background-color 0.2s ease;
}
.menu-list a:hover {
background: #f8f9fa;
color: #667eea;
}
.dark-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
z-index: 150;
opacity: 0;
visibility: hidden;
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.dark-overlay.active {
opacity: 1;
visibility: visible;
}
.main-content {
margin-top: 60px;
padding: 20px;
}
④ JavaScript
document.addEventListener('DOMContentLoaded', function() {
const menuToggle = document.getElementById('menuToggle');
const sideMenu = document.getElementById('sideMenu');
const closeMenu = document.getElementById('closeMenu');
const darkOverlay = document.getElementById('darkOverlay');
// メニューを開く
menuToggle.addEventListener('click', function() {
sideMenu.classList.add('active');
darkOverlay.classList.add('active');
menuToggle.classList.add('active');
});
// メニューを閉じる
function closeSideMenu() {
sideMenu.classList.remove('active');
darkOverlay.classList.remove('active');
menuToggle.classList.remove('active');
}
// 閉じるボタンでメニューを閉じる
closeMenu.addEventListener('click', closeSideMenu);
// ダークオーバーレイクリックでメニューを閉じる
darkOverlay.addEventListener('click', closeSideMenu);
// ESCキーでメニューを閉じる
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && sideMenu.classList.contains('active')) {
closeSideMenu();
}
});
});
⑤ カスタマイズ例
/* より暗いオーバーレイ */
.dark-overlay {
background: rgba(0, 0, 0, 0.9);
}
/* オーバーレイ速度の変更 */
.dark-overlay {
transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
/* グラデーションオーバーレイ */
.dark-overlay {
background: linear-gradient(135deg, rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0.6));
}
/* カラーオーバーレイ */
.dark-overlay {
background: linear-gradient(135deg, rgba(102, 126, 234, 0.8), rgba(0, 0, 0, 0.7));
}
まとめ
今回ご紹介したサイドメニュー表示アニメーションは、Webサイトのユーザーエクスペリエンスを向上させる重要な要素です。
実装のコツ
- 適切なアニメーション時間(300ms〜500ms)
- スムーズなイージング関数の使用
- モバイルデバイスでの動作確認
- アクセシビリティの配慮
- パフォーマンスの最適化
避けるべきポイント
- 過度に複雑なアニメーション
- 長すぎるアニメーション時間
- 読みにくい色の組み合わせ
- パフォーマンスを考慮しない実装
- 過度な使用
おすすめの組み合わせ
- モバイルサイト: スライドイン、オーバーレイ
- タブレット対応: プッシュ、ブラー
- デスクトップ: ダークオーバーレイ



特にモバイルサイトやタブレット対応では、サイドメニュー表示アニメーションがユーザーエクスペリエンスを大きく左右します。この記事のコードをご活用いただき、より魅力的なWebサイトの制作に繋がれば何よりです。
あわせて読みたい
もっと効率的にWeb制作を学びたい方へ
Web制作の学習は楽しいものですが、一人で進めていると「これで合っているのかな?」と不安になることもありますよね。
僕も独学でWeb制作を学んできましたが、今思うと「もっと早く知りたかった」と思うことがたくさんあります。
特に以下のような方は、一度プログラミングスクールの利用を検討してみることをおすすめします。
- 学習の方向性に迷いがある方
- 効率的にスキルを身につけたい方
- 転職や副業でWeb制作を活用したい方
- 挫折経験がある方
忍者CODEなら、業界最安値で24時間サポート付きの学習環境が整っています。


コメント