편집 요약 없음 태그: 수동 되돌리기 |
편집 요약 없음 |
||
| 11번째 줄: | 11번째 줄: | ||
// 접기 상태일 때 | // 접기 상태일 때 | ||
content.style.maxHeight = null; // 접기 | content.style.maxHeight = null; // 접기 | ||
} else { | } else { | ||
// 펼치기 상태일 때 | // 펼치기 상태일 때 | ||
content.style.maxHeight = content.scrollHeight + "px"; // 실제 높이로 설정하여 펼치기 | content.style.maxHeight = content.scrollHeight + "px"; // 실제 높이로 설정하여 펼치기 | ||
} | } | ||
}); | }); | ||
}); | }); | ||
}); | }); | ||
2025년 1월 13일 (월) 16:38 판
document.addEventListener('DOMContentLoaded', function () {
const collapsibles = document.querySelectorAll('.mw-collapsible');
collapsibles.forEach(function(collapsible) {
const trigger = collapsible.querySelector('.mw-collapsible-toggle'); // 펼치기/접기 버튼
const content = collapsible.querySelector('.mw-collapsible-content'); // 펼쳐질 내용
// 펼치기/접기 버튼 클릭 시
trigger.addEventListener('click', function() {
if (content.style.maxHeight) {
// 접기 상태일 때
content.style.maxHeight = null; // 접기
} else {
// 펼치기 상태일 때
content.style.maxHeight = content.scrollHeight + "px"; // 실제 높이로 설정하여 펼치기
}
});
});
});