var dep1; var dep2; var dep3; jQuery(function($){ /* *********************** PC NAV ************************ */ var $gnbBg = $('.gnb-overlay-bg'); // PC var $gnb = $("#gnb"); var gnb_first_height = $gnb.innerHeight(); var $gnbList = $("#gnb > ul"); var $gnb_dep1 = $("#gnb > ul > li"); var $gnb_dep2 = $("#gnb > ul > li .gnb-2dep"); var $snb = $(".snb"); // 모바일 var $menuBtn = $("#header .nav-open-btn"); var $gnbM = $("#gnbM"); var $gnbMList = $gnbM.find(".gnb-m-tab-content-wrapper").children(".cm-tab-con").children(".navigation").children("li"); var menuState = false; gnb_on(); // gnb 각각메뉴 function gnb_on () { $gnbList.children("li").children("a").on("mouseenter focus",function () { var gnb_height = $(this).siblings('.gnb-2dep').innerHeight(); //if( !($(this).siblings('.gnb-2dep').hasClass("show")) ){ // if( $(this).siblings('.gnb-2dep').css('display') == 'none'){ $gnb.css("height",gnb_height);//.stop().animate({"height":gnb_height},400,"easeOutCubic"); $("#gnbBg").css("height",gnb_height).addClass("open");//.stop().animate({"height":gnb_height},400,"easeOutCubic"); $gnbList.children("li").removeClass("on").children(".gnb-2dep").removeClass("show");//.hide(); $(this).parent("li").addClass("on").children(".gnb-2dep").addClass("show")//.delay(200).stop().fadeIn(800); $gnbBg.addClass("show"); //} }) $gnbList.on("mouseleave",gnb_return); $gnbList.find("a").last().on("focusout",gnb_return); function gnb_return () { $gnbList.children("li").removeClass("on").children(".gnb-2dep").removeClass("show");//.hide(); $gnb.stop().css("height",gnb_first_height);//.animate({"height":gnb_first_height},400,"easeOutCubic"); $("#gnbBg").css("height",135).removeClass("open");//.animate({"height":0},400,"easeOutCubic"); $gnbBg.removeClass("show"); $(".nav-on-icon").hide(); if ( dep1 > 0 && dep2 ) { $gnbList.children("li").eq(dep1-1).addClass("active"); } } } /* 오버하거나 포커스가 있을경우 활성화 */ $gnb_dep1.on("mouseenter focusin",function(){ var navPosition = $(this).position().left; /* bar의 시작점은 li의 left 좌표 */ var navPadding = parseInt($(this).children("a").css("padding-left")); var navWidth = $(this).children("a").children("span").outerWidth(); /* bar 길이 li > a의 길이와 같게 */ $(".nav-on-icon").show().stop().animate({left:navPosition+navPadding,width:navWidth},400,"easeOutCubic"); }); // gnb 2차 메뉴에 마우스 올렸을때 대메뉴 on $gnb_dep2.hover(function(){ $(this).parent("li").addClass("on"); },function () { $gnb_dep1.removeClass("on"); }); // 서브메뉴에서 해당메뉴 on if ( dep1 > 0 && dep2 > 0) { //$gnb_dep1.eq(dep1-1).addClass("on"); $gnbList.children("li").eq(dep1-1).addClass("active"); $gnbMList.eq(dep1-1).addClass("on"); $snb.each(function () { $(this).find("li").eq(dep2-1).addClass("on"); }); } /* *********************** MOBILE NAV ************************ */ $menuBtn.click(function () { if ( menuState ) { menuClose(); menuState = false; $(this).removeClass("active"); }else { menuOpen(); menuState = true; $(this).addClass("active"); } return false; }); $gnbBg.click(function () { menuClose(); menuState = false; $menuBtn.removeClass("active"); }); /* 메뉴열기 */ function menuOpen () { $gnbM.addClass("open"); $gnbBg.fadeIn(); $("body").css({'height':$(window).height(), 'overflow':'hidden'}); } /* 메뉴닫기 */ function menuClose () { $gnbM.removeClass("open"); $gnbBg.hide(); $("body").css({'height':'auto', 'overflow':'auto'}); } /* GNB MOBILE 2DEPTH 클래스 붙이기 */ $("#gnbM .navigation > li:has('.gnb-2dep')").addClass("has-2dep"); $("#gnbM .navigation > li:has('.gnb-2dep')").each(function () { $(this).children("a").append(""); }); $("#gnbM .navigation.gnb2 > li, #gnbM .navigation.gnb4 > li:first-child, #gnbM .navigation.gnb4 > li:last-child").each(function () { $(this).children("a").append(""); }); /* GNB MOBILE 2DEPTH 오픈 */ $("#gnbM .navigation > li:has('.gnb-2dep')").children("a").click(function(event){ /* 2dep가 열려있을때 */ if ( $(this).parent("li").hasClass("active") ){ $(this).parent("li").removeClass("active"); $(this).children(".open-icon").hide(); $(this).children(".close-icon").show(); $(this).siblings(".gnb-2dep").slideUp(400); } /* 2dep가 닫혀있을때 */ else{ $("#gnbM .navigation > li").has(".gnb-2dep").each(function() { if ( $(this).hasClass("active") ){ $(this).removeClass("active"); $(this).find(".open-icon").hide(); $(this).find(".close-icon").show(); $(this).children(".gnb-2dep").slideUp(400); } }); $(this).parent("li").addClass("active"); $(this).children(".close-icon").hide(); $(this).children(".open-icon").show(); $(this).siblings(".gnb-2dep").slideDown(400); } return false; }); /* 해당페이지의 GNB 모바일 열기 */ if ( dep1> 0 && dep2> 0 ) { $gnbM.children("ul").children("li").eq(dep1-1).addClass("active").children(".gnb-2dep").show(); $gnbM.children("ul").children("li").eq(dep1-1).find(".close-icon").hide(); $gnbM.children("ul").children("li").eq(dep1-1).find(".open-icon").show(); // 모바일 네비 on } /* *********************** PC, 모바일 공통 ************************ */ // dep3 존재 할 때 메뉴 이동 & 없을 때 메뉴 이동 var $sub_prev_page_btn = $(".sub-prev-page-btn"); var $sub_next_page_btn = $(".sub-next-page-btn"); if (dep3) { var $dep3_menu = $(".menu-location.location2 > ul > li"); var dep3_menu_lang = $dep3_menu.length; $sub_prev_page_btn.attr("href",$dep3_menu.eq(dep3-2).children("a").attr("href")); $sub_next_page_btn.attr("href",$dep3_menu.eq(dep3).children("a").attr("href")); if ( dep3 == dep3_menu_lang ) { $sub_next_page_btn.attr("href",$dep3_menu.eq(0).children("a").attr("href")); }else if ( dep3 == 1 ) { $sub_prev_page_btn.attr("href",$dep3_menu.eq(dep3_menu_lang-1).children("a").attr("href")); } }else { var $dep2_menu = $(".menu-location.location1 > ul > li"); var dep2_menu_lang = $dep2_menu.length; $sub_prev_page_btn.attr("href",$dep2_menu.eq(dep2-2).children("a").attr("href")); $sub_next_page_btn.attr("href",$dep2_menu.eq(dep2).children("a").attr("href")); if ( dep2 == dep2_menu_lang ) { $sub_next_page_btn.attr("href",$dep2_menu.eq(0).children("a").attr("href")); }else if ( dep2 == 1 ) { $sub_prev_page_btn.attr("href",$dep2_menu.eq(dep2_menu_lang-1).children("a").attr("href")); } } /* ------------------------ *** 서브 상단 location (1차,2차) 하위메뉴 펼치기 *** ------------------------ */ $(".menu-location > .cur-location").click(function () { //$(".menu-location .location-menu-con:visible").hide(); $(this).toggleClass("open"); $(this).siblings().slideToggle(500); return false; }); $(".menu-location").mouseleave(function () { if ( $(this).find(".location-menu-con").css("display") == "block" ) { $(this).find(".cur-location").removeClass("open"); $(this).find(".location-menu-con").slideUp(500); } }); });