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

편집 요약 없음
편집 요약 없음
1번째 줄: 1번째 줄:
/* 이 자바스크립트 설정은 리버티 스킨을 사용하는 사용자에게 적용됩니다 */
$(document).ready(function() {
$(document).ready(function() {
  // 클릭 이벤트 핸들러
   $('.mw-collapsible').click(function() {
   $('.mw-collapsible').click(function() {
     var content = $(this).find('.mw-collapsible-content');
     var content = $(this).find('.mw-collapsible-content');
     var currentHeight = content.height(); // 현재 높이
     var currentHeight = content.height(); // 현재 높이
     var targetHeight = content[0].scrollHeight; // 실제 내용의 높이
     var targetHeight = content[0].scrollHeight; // 실제 콘텐츠의 전체 높이
      
      
    // 표가 접혀 있으면 펼치고, 펼쳐져 있으면 접기
     if (currentHeight === 0) {
     if (currentHeight === 0) {
       // 펼칠 때: 콘텐츠 높이를 0에서 실제 높이로 애니메이션
       // 펼칠 때: 애니메이션으로 높이 변경
       animateHeight(content, 0, targetHeight);
       animateHeight(content, 0, targetHeight);
     } else {
     } else {
       // 접을 때: 콘텐츠 높이를 실제 높이에서 0으로 애니메이션
       // 접을 때: 애니메이션으로 높이 변경
       animateHeight(content, currentHeight, 0);
       animateHeight(content, currentHeight, 0);
     }
     }
26번째 줄: 27번째 줄:
         var newHeight = startHeight + (endHeight - startHeight) * progress;
         var newHeight = startHeight + (endHeight - startHeight) * progress;
         element.height(newHeight); // 새로운 높이 설정
         element.height(newHeight); // 새로운 높이 설정
         requestAnimationFrame(step); // 계속 애니메이션
         requestAnimationFrame(step); // 계속 애니메이션 진행
       } else {
       } else {
         element.height(endHeight); // 마지막에 정확한 높이 설정
         element.height(endHeight); // 마지막에 정확한 높이 설정

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

$(document).ready(function() {
  // 클릭 이벤트 핸들러
  $('.mw-collapsible').click(function() {
    var content = $(this).find('.mw-collapsible-content');
    var currentHeight = content.height(); // 현재 높이
    var targetHeight = content[0].scrollHeight; // 실제 콘텐츠의 전체 높이
    
    // 표가 접혀 있으면 펼치고, 펼쳐져 있으면 접기
    if (currentHeight === 0) {
      // 펼칠 때: 애니메이션으로 높이 변경
      animateHeight(content, 0, targetHeight);
    } else {
      // 접을 때: 애니메이션으로 높이 변경
      animateHeight(content, currentHeight, 0);
    }
  });

  // 애니메이션 함수
  function animateHeight(element, startHeight, endHeight) {
    var startTime = null;
    var duration = 500; // 애니메이션 지속 시간 (밀리초)

    function step(timestamp) {
      if (!startTime) startTime = timestamp;
      var progress = (timestamp - startTime) / duration;
      if (progress < 1) {
        var newHeight = startHeight + (endHeight - startHeight) * progress;
        element.height(newHeight); // 새로운 높이 설정
        requestAnimationFrame(step); // 계속 애니메이션 진행
      } else {
        element.height(endHeight); // 마지막에 정확한 높이 설정
      }
    }
    requestAnimationFrame(step); // 애니메이션 시작
  }
});