アコーディオン:グラデーション|Accordion: Gradient

  • Beautiful gradient background
  • Colorful and attractive
  • Button with icon
  • Smooth animation
  • Visually impactful design

HTML
<div class="container">
    <div class="btn-box">
        <button data-default-text="Gradient Accordion" data-open-text="Close">Gradient Accordion</button>
    </div>
    <div class="more">
        <ul>
            <li>Beautiful gradient background</li>
            <li>Colorful and attractive</li>
            <li>Button with icon</li>
            <li>Smooth animation</li>
            <li>Visually impactful design</li>
        </ul>
    </div>
</div>
CSS
@keyframes fadeIn {
  0% {
    opacity: 0;
    transform: translateY(-10px);
  }
  100% {
    opacity: 1;
    transform: none;
  }
}

.container {
  margin-bottom: 30px;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.container .btn-box button {
  width: 100%;
  padding: 18px 25px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: left;
  position: relative;
  overflow: hidden;
}

.container .btn-box button::before {
  content: '▼';
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  transition: transform 0.3s ease;
}

.container .btn-box button:hover {
  background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
  transform: scale(1.02);
}

.container .more {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.5s ease;
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  border-radius: 0 0 10px 10px;
  margin-top: -5px;
}

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

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

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

.container .more li {
  padding: 10px 0;
  color: #fff;
  font-weight: 500;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.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をコピーしました!
目次