19 lines
804 B
JavaScript
19 lines
804 B
JavaScript
document.addEventListener('DOMContentLoaded', function() {
|
|
document.querySelectorAll('details').forEach(details => {
|
|
const summary = details.querySelector('summary');
|
|
const content = details.querySelector('.details-content');
|
|
|
|
details.addEventListener('toggle', function() {
|
|
if (details.open) {
|
|
// 计算内容高度并设置为CSS变量
|
|
const height = content.scrollHeight;
|
|
details.style.setProperty('--details-content-height', `${height}px`);
|
|
|
|
// 动画结束后移除固定高度
|
|
setTimeout(() => {
|
|
details.style.removeProperty('--details-content-height');
|
|
}, 300);
|
|
}
|
|
});
|
|
});
|
|
}); |