미디어위키:Liberty.js: 두 판 사이의 차이

편집 요약 없음
편집 요약 없음
11번째 줄: 11번째 줄:
         // 접기 상태일 때
         // 접기 상태일 때
         content.style.maxHeight = null;  // 접기
         content.style.maxHeight = null;  // 접기
         content.style.transform = "translateY(-20px)";  // 위로 애니메이션
         content.style.transform = "translateY(-20px)";  // 접을 때 위로 이동
       } else {
       } else {
         // 펼치기 상태일 때
         // 펼치기 상태일 때
         content.style.maxHeight = content.scrollHeight + "px";  // 실제 내용의 높이에 맞춰 펼치기
         content.style.maxHeight = content.scrollHeight + "px";  // 실제 높이로 설정하여 펼치기
         content.style.transform = "translateY(0)";  // 원래 위치로 이동
         content.style.transform = "translateY(0)";  // 펼칠 때 원래 위치로 돌아옴
       }
       }
     });
     });
   });
   });
});
});

2025년 1월 13일 (월) 16:36 판

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;  // 접기
        content.style.transform = "translateY(-20px)";  // 접을 때 위로 이동
      } else {
        // 펼치기 상태일 때
        content.style.maxHeight = content.scrollHeight + "px";  // 실제 높이로 설정하여 펼치기
        content.style.transform = "translateY(0)";  // 펼칠 때 원래 위치로 돌아옴
      }
    });
  });
});