Anime Expand Card
anime.jsでクリック時にカードが拡大しコンテンツが表示されるエキスパンドカード。
HTML
<div class="aec-card" id="aec-card"> <h3 class="aec-title">Expand</h3> <p class="aec-detail" id="aec-detail">This content reveals when you click the card. Click again to collapse.</p> </div>
CSS
.aec-card {
width: 240px;
padding: 24px;
background: #1e293b;
border-radius: 16px;
color: #e2e8f0;
cursor: pointer;
overflow: hidden;
}
.aec-title {
margin: 0;
font-size: 18px;
}
.aec-detail {
margin: 12px 0 0;
font-size: 13px;
opacity: 0;
max-height: 0;
overflow: hidden;
line-height: 1.6;
}
JavaScript
const card = document.getElementById('aec-card');
const detail = document.getElementById('aec-detail');
let expanded = false;
card.addEventListener('click', function() {
expanded = !expanded;
anime({
targets: detail,
maxHeight: expanded ? [0, 80] : [80, 0],
opacity: expanded ? [0, 1] : [1, 0],
duration: 500,
easing: 'easeOutCubic'
});
anime({
targets: card,
scale: expanded ? [1, 1.03, 1] : 1,
duration: 400,
easing: 'easeOutElastic(1, 0.6)'
});
});