アコーディオン:アイコン|Accordion: Icon

  • プラス/マイナスアイコン付き
  • アイコンの回転アニメーション
  • 直感的な操作感
  • 視覚的なフィードバック
  • ユーザビリティ重視のデザイン

HTML
<div class="container">
    <div class="btn-box">
        <button data-default-text="アイコンアコーディオン" data-open-text="閉じる">アイコンアコーディオン</button>
    </div>
    <div class="more">
        <ul>
            <li>プラス/マイナスアイコン付き</li>
            <li>アイコンの回転アニメーション</li>
            <li>直感的な操作感</li>
            <li>視覚的なフィードバック</li>
            <li>ユーザビリティ重視のデザイン</li>
        </ul>
    </div>
</div>
CSS
@keyframes fadeIn {
  0% {
    opacity: 0;
    transform: translateY(-10px);
  }
  100% {
    opacity: 1;
    transform: none;
  }
}

.container {
  margin-bottom: 30px;
}

.container .btn-box button {
  width: 100%;
  padding: 20px 25px;
  background: #f8f9fa;
  border: 2px solid #e9ecef;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  color: #495057;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: left;
  position: relative;
}

.container .btn-box button::before {
  content: '+';
  position: absolute;
  right: 25px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 20px;
  font-weight: bold;
  color: #2196f3;
  transition: transform 0.3s ease;
}

.container .btn-box button:hover {
  background: #e9ecef;
  border-color: #2196f3;
  color: #2196f3;
}

.container .more {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  background: #fff;
  border: 2px solid #e9ecef;
  border-top: none;
  border-radius: 0 0 8px 8px;
}

.container .more.appear {
  max-height: 300px;
  animation: fadeIn 0.3s ease;
}

.container:has(.more.appear) .btn-box button::before {
  transform: translateY(-50%) rotate(45deg);
}

.container .more ul {
  list-style: none;
  padding: 20px 32px;
  margin: 0;
}

.container .more li {
  padding: 12px 0;
  color: #495057;
  border-bottom: 1px solid #e9ecef;
  font-weight: 500;
  position: relative;
}

.container .more li::before {
  content: '•';
  position: absolute;
  left: -16px;
  color: #2196f3;
  font-weight: bold;
}

.container .more li:last-child {
  border-bottom: none;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
  .container .btn-box button {
    font-size: 14px;
    padding: 15px 20px;
  }
  
  .container .more ul {
    padding: 15px;
  }
}
JavaScript
document.addEventListener('DOMContentLoaded', function() {
    const button = document.querySelector('.btn-box button');
    const content = document.querySelector('.more');
    
    button.addEventListener('click', function() {
        content.classList.toggle('appear');
        
        // ボタンテキストの切り替え
        if (content.classList.contains('appear')) {
            this.textContent = this.dataset.openText || '閉じる';
        } else {
            this.textContent = this.dataset.defaultText;
        }
    });
});
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次