Accordion / 001 — シンプル|Simple
デザイン見本
- Simple and user-friendly design
- Basic open/close animation
- Responsive design
基本的な枠線付きのシンプルアコーディオン。 汎用性が高く、どんなサイトにも馴染みやすいデザインです。 開閉時にフェードインアニメーションが適用され、スムーズな印象を与えます。
実装コード
HTML
<div class="container">
<div class="btn-box">
<button data-default-text="Simple Accordion" data-open-text="Close">Simple Accordion</button>
</div>
<div class="more">
<ul>
<li>Simple and user-friendly design</li>
<li>Basic open/close animation</li>
<li>Responsive design</li>
</ul>
</div>
</div>
CSS
/* アニメーション定義 */
@keyframes acc1-fadeIn {
0% {
opacity: 0;
transform: translateY(-10px)
}
100% {
opacity: 1;
transform: none
}
}
.container {
width: 100%;
}
.container .btn-box button {
width: 100%;
padding: 16px 20px;
background: #fff;
border: 2px solid #ddd;
border-radius: 8px;
font-size: 14px;
font-weight: 600;
color: #333;
cursor: pointer;
transition: all 0.3s ease;
text-align: left;
}
.container .btn-box button:hover {
background: #f8f9fa;
border-color: #adb5bd;
}
.container .more {
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
background: #fff;
border: 2px solid #ddd;
border-top: none;
border-radius: 0 0 8px 8px;
}
.container .more.appear {
max-height: 200px;
animation: acc1-fadeIn 0.3s ease;
}
.container .more ul {
list-style: none;
padding: 12px 16px;
margin: 0;
}
.container .more li {
padding: 8px 0;
color: #666;
border-bottom: 1px solid #eee;
font-size: 13px;
}
.container .more li:last-child {
border-bottom: none;
}
JS
document.addEventListener("DOMContentLoaded", () => {
document.querySelectorAll('.container').forEach(container => {
const button = container.querySelector('.btn-box button');
const content = container.querySelector('.more');
if (button && content) {
button.addEventListener('click', function() {
content.classList.toggle('appear');
// ボタンテキストの切り替え
if (content.classList.contains('appear')) {
this.textContent = this.dataset.openText || 'Close';
} else {
this.textContent = this.dataset.defaultText;
}
});
}
});
});