$(document).ready(function () { let timeout; // 전역 타임아웃 변수 let allWrapperTimeout; //let hideTimeout; // 숨기기 타임아웃을 위한 변수 let tabChangeTimeout; let mouseInDMenu = false; // d-menu에 마우스가 있는지 확인하는 플래그 // 모든 드롭다운 메뉴 닫기 함수 function closeAllDMenus() { $(".d-menu").slideUp(); $(".open-all").text("모두 열기"); $(".d-icon").attr("src", "/images/plus_icon.png"); } // d-menu에 마우스가 들어갔을 때와 나갔을 때 처리 $(".d-menu").on("mouseenter", function () { mouseInDMenu = true; }).on("mouseleave", function () { mouseInDMenu = false; setTimeout(checkCloseTaxWrapper, 100); // 100ms 후에 닫힘 체크 }); // 네비게이션 아이템 클릭 처리 $("#navi-menu .nv-item").on("click", function (event) { // 클릭한 아이템의 바로 다음에 있는 드롭다운 메뉴(d-menu)를 선택 const dropdownMenu = $(this).next(".d-menu"); // 드롭다운 메뉴가 존재하지 않으면 아무 동작도 하지 않고 리턴 if (dropdownMenu.length === 0) return; // 기본 클릭 이벤트와 상위 이벤트의 전파를 막음 event.preventDefault(); event.stopPropagation(); // 모든 다른 드롭다운 메뉴를 닫고, 아이콘을 플러스 아이콘으로 변경 $(".d-menu").not(dropdownMenu).slideUp().prev().find(".d-icon").attr("src", "/images/plus_icon.png"); // 현재 클릭된 아이템의 d-icon을 선택 const dIcon = $(this).find(".d-icon"); // 드롭다운 메뉴가 보이는 상태라면, 슬라이드업으로 닫고 아이콘을 플러스 아이콘으로 변경 if (dropdownMenu.is(":visible")) { dropdownMenu.slideUp(); dIcon.attr("src", "/images/plus_icon.png"); } else { // 드롭다운 메뉴가 보이지 않으면 display를 flex로 설정하고 슬라이드다운으로 열기 dropdownMenu.css("display", "flex").hide().slideDown(); dIcon.attr("src", "/images/minus_icon.png"); } }); // "모두 열기" / "모두 닫기" 버튼 클릭 이벤트 처리 $(document).on("click", ".open-all", function () { const openButton = $(this); if (openButton.text() === "모두 열기") { setTimeout(() => { openButton.text("모두 닫기"); // openButton.parent().find(".d-menu").slideDown(); openButton.parent().find(".d-menu").css("display", "flex").hide().slideDown(); $(".d-icon").attr("src", "/images/minus_icon.png"); }); } else { openButton.text("모두 열기"); closeAllDMenus(); } }); // "전체 메뉴" 초기화 $(".menu-all").on("mouseenter", function () { clearTimeout(allWrapperTimeout); //$(".all-wrapper").stop().slideDown(200); // "전체 메뉴" 슬라이드다운 // allWrapperTimeout = setTimeout(initializeMenuTabs, 200); // 200ms 후 탭 초기화 호출 allWrapperTimeout = setTimeout(function() { $(".all-wrapper").stop().slideUp(200, function() { $(this).css('height', ''); // 높이 초기화, 전체 메뉴 height가 맞지 않음. }); }, 300); initializeMenuTabs(); // 메뉴 탭 초기화 함수 호출 }).on("mouseleave", function () { clearTimeout(allWrapperTimeout); //$(".all-wrapper").stop().slideUp(200); // 서브메뉴 슬라이드업 allWrapperTimeout = setTimeout(function() { $(".all-wrapper").stop().slideUp(200); // 일정 시간 후 서브메뉴 슬라이드업 }, 300); // 300ms 지연 후 슬라이드업 }); // "전체 메뉴" 탭 클릭 처리 $(".gnb-tab-item").on("click", function (e) { // 현재 클릭한 탭에 "on" 클래스를 추가 $(this).addClass("on").siblings().removeClass("on"); // 탭의 인덱스를 가져옴 const idx = $(this).index(); // 인덱스에 해당하는 탭 콘텐츠에 "on" 클래스를 추가하고 나머지 제거 //$(".gnb-tab-content").eq(idx).addClass("on").siblings().removeClass("on"); // 기존에 설정된 지연을 초기화 clearTimeout(tabChangeTimeout); // 새로운 지연 타이머 설정 tabChangeTimeout = setTimeout(function() { $(".all-wrapper").stop().slideDown(200); // "전체 메뉴" 슬라이드다운 $(".gnb-tab-content").eq(idx).addClass("on").siblings().removeClass("on"); }, 200); // 200ms 지연 후 실행 }); // 메뉴 탭 초기화 함수 function initializeMenuTabs() { // 첫 번째 탭과 첫 번째 콘텐츠에 "on" 클래스 추가 $(".gnb-tab-item").first().addClass("on").siblings().removeClass("on"); $(".gnb-tab-content").first().addClass("on").siblings().removeClass("on"); } // Navi 메뉴 서브 처리 $('.Navi > li.nv-row').mouseenter(function () { var $this = $(this); timeout = window.setTimeout(function () { $this.find('.gnb-sub').finish().stop().slideDown(200); // 서브메뉴 슬라이드다운 }, 400); // 400ms 딜레이 추가 }); $('.Navi > li.nv-row').mouseleave(function () { if (timeout) window.clearTimeout(timeout); clearTimeout(allWrapperTimeout); // allWrapperTimeout 초기화 추가 $(this).find('.gnb-sub').finish().stop().slideUp(200); // 서브메뉴 슬라이드업 // 모든 다른 드롭다운 메뉴를 닫고, 아이콘을 플러스 아이콘으로 변경 $(".d-menu").slideUp().prev().find(".d-icon").attr("src", "/images/plus_icon.png"); }); });