$(document).ready(function () { // ********** header 메뉴 ********** $('nav > ul > li').hover( function () { $(this).children('.subnav').stop(true).slideDown(400); }, function () { $(this).children('.subnav').stop(true).slideUp(300); } ); // ********** header 스크롤 효과 ********** var path = window.location.pathname; var page = path.split('/').pop(); var isMainPage = page === '' || page === 'index.html' || page === 'index.php'; // 서브페이지는 body에 subpage 클래스 추가 if (!isMainPage) { $("body").addClass("subpage"); } $(window).scroll(function () { const scroll_top = $(this).scrollTop(); if (scroll_top >= 30) { $("header").addClass("on"); } else { $("header").removeClass("on"); } }); // ********** section5 둘러보기 ********** var Swiper1 = new Swiper('.mainindex .mySwiper1', { loop: true, speed: 900, observer: true, loopedSlides: 10, slidesPerView: 1, spaceBetween: 20, autoplay: { delay: 2500, disableOnInteraction: false }, navigation: { nextEl: "#section5 .swiper-button-next", prevEl: "#section5 .swiper-button-prev", }, }); // ********** sub10102 둘러보기 ********** var Swiper3 = new Swiper('.sub10102 .mySwiper1', { loop: true, speed: 900, observer: true, loopedSlides: 10, slidesPerView: 1, spaceBetween: 20, autoplay: { delay: 2500, disableOnInteraction: false }, navigation: { nextEl: ".sub10102 .swiper-button-next", prevEl: ".sub10102 .swiper-button-prev", }, }); // ********** sub30101 s1 ********** var Swiper2 = new Swiper('.sub30101 .mySwiper2', { loop: true, speed: 1000, observer: true, loopedSlides: 10, slidesPerView: 1, spaceBetween: 0, autoplay: { delay: 4000, disableOnInteraction: false }, pagination: { el: ".sub30101 .swiper-pagination", clickable: true, }, }); // 아코디언 메뉴 ******************** (중첩 제거!) $('.subtop .accordionMenu').hide(); $('.subtop .accordionContent').hide(); // 메뉴 버튼 클릭 $('.subtopMenu .menu').click(function (e) { e.stopPropagation(); // 화살표 회전 $(this).find('img').toggleClass('rotate'); $('.subtop .accordionMenu').stop().slideToggle(350); }); // 아코디언 헤더 클릭 $('.accordionHeader').click(function () { const $content = $(this).next('.accordionContent'); const $header = $(this); // 다른 아코디언 닫기 $('.accordionHeader').not($header).removeClass('active'); $('.accordionContent').not($content).stop().slideUp(350); // 현재 아코디언 토글 $header.toggleClass('active'); $content.stop().slideToggle(350); }); // 외부 클릭시 메뉴 닫기 $(document).click(function () { $('.subtop .accordionMenu').stop().slideUp(350); $('.subtopMenu .menu img').removeClass('rotate'); }); // 메뉴 내부 클릭시 이벤트 전파 방지 $('.subtop .accordionMenu').click(function (e) { e.stopPropagation(); }); // 페이지 로드시 현재 위치 표시 setActiveMenu(); // 페이지 로드시 현재 위치 표시 함수 function setActiveMenu() { var currentPath = window.location.pathname; // sub1/01/01.php 또는 sub1_01_01.php 형식 둘 다 매칭 var pathMatch = currentPath.match(/sub(\d+)[_\/](\d+)[_\/](\d+)\.(html|php)$/); if (pathMatch) { // 각 아코디언 아이템 확인 $('.accordionItem').each(function (index) { var $accordionItem = $(this); var isFirstAccordion = (index === 0); // 해당 아코디언의 링크들 확인 $accordionItem.find('.accordionContent li a').each(function () { var href = $(this).attr('href'); var hrefMatch = href.match(/sub(\d+)[_\/](\d+)[_\/](\d+)\.(html|php)$/); if (hrefMatch && pathMatch) { var isMatch = false; if (isFirstAccordion) { // 첫 번째 아코디언: 앞 2자리만 비교 (sub1_01) isMatch = (hrefMatch[1] === pathMatch[1] && hrefMatch[2] === pathMatch[2]); } else { // 나머지 아코디언: 전체 비교 (sub1_01_01) isMatch = (hrefMatch[1] === pathMatch[1] && hrefMatch[2] === pathMatch[2] && hrefMatch[3] === pathMatch[3]); } if (isMatch) { // 현재 페이지 링크에 active 클래스 추가 $(this).parent('li').addClass('active'); // 해당 아코디언만 자동으로 열기 (애니메이션 없이) $accordionItem.find('.accordionHeader').addClass('active'); $accordionItem.find('.accordionContent').show(); } } }); }); } } });