var dep1; var dep2; jQuery(function($){ /* PC Gnb */ var $openMenu = $(".cm-top-menu"); // PC var $gnb = $("#gnb"); var $gnbList = $("#gnb > ul"); var $gnb_dep1 = $("#gnb > ul > li"); var $gnb_dep2 = $("#gnb > ul > li .gnb-2dep"); var $gnbBg = $('.gnb-overlay-bg'); var $snb = $(".snb"); // Mobile var $menuBtn = $("#header .nav-open-btn"); var $gnbM = $("#gnbM"); var $gnbMList = $gnbM.children("#navigation").children("li"); var $gnbMBg = $('.gnb-overlay-bg-m'); var menuState = false; $(window).resize(function () { var win_width = $(window).outerWidth(); if ( menuState ) { if ( win_width > 1200 ) { $("body").css({'height':'auto', 'overflow':'auto'}); } } }); if ( $gnb.is(".total-menu") ) { gnb_total_on(); }else if ( $gnb.is(".each-menu") ) { gnb_each_on(); } // Gnb function gnb_total_on () { $gnbList.children("li").children("a").on("mouseenter focus",function () { if( $gnb_dep2.css('display') == 'none'){ $("#header").addClass("over"); $gnb_dep2.stop().slideDown("fast"); $gnb.find('#gnbBg').stop().slideDown("fast"); $gnbBg.stop().fadeIn(); } }) $gnbList.on("mouseleave",gnb_return); $gnbList.find("a").last().on("focusout",gnb_return); function gnb_return () { if( $gnb_dep2.css('display') == 'block'){ $("#header").removeClass("over"); $gnb_dep2.stop().slideUp("fast"); $gnb.find('#gnbBg').stop().slideUp("fast"); //$gnbBg.hide(); } if ( dep1 > 0 && dep2 ) { $gnbList.children("li").eq(dep1-1).addClass("active"); } } } function gnb_each_on () { $gnbList.children("li").children("a").on("mouseenter focus",function () { $gnbList.children("li").removeClass("on").children(".gnb-2dep").hide(); $(this).parent("li").addClass("on").children(".gnb-2dep").stop().slideDown(500); }) $gnbList.on("mouseleave",gnb_return); $gnbList.find("a").last().on("focusout",gnb_return); function gnb_return () { $gnbList.children("li").removeClass("on").children(".gnb-2dep").hide(); if ( dep1 > 0 && dep2 ) { $gnbList.children("li").eq(dep1-1).addClass("active"); } } } // Gnb 2depth mouse over > 1depth on $gnb_dep2.hover(function(){ $(this).parent("li").addClass("on"); },function () { $gnb_dep1.removeClass("on"); }); // Menu on if ( dep1 > 0 && dep2 > 0) { $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 Gnb */ $menuBtn.click(function () { if ( menuState ) { menuClose(); menuState = false; $(this).removeClass("active"); }else { menuOpen(); menuState = true; $(this).addClass("active"); } return false; }); $gnbMBg.click(function () { menuClose(); menuState = false; $menuBtn.removeClass("active"); }); // Open function menuOpen () { $gnbM.addClass("open"); $gnbMBg.fadeIn(); $("").css({'height':$(window).height(), 'overflow':'hidden'}); } // Close function menuClose () { $gnbM.removeClass("open"); $gnbMBg.hide(); $("").css({'height':'auto', 'overflow':'auto'}); } //2depth addClass $("#gnbM > ul > li:has('.gnb-2dep')").addClass("has-2dep"); $("#gnbM > ul > li:has('.gnb-2dep')").each(function () { $(this).children("a").append("+"); }); //2depth Open $("#gnbM > ul > li:has('.gnb-2dep')").children("a").click(function(event){ 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); }else{ $("#gnbM > ul > 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; }); // 2depth Open if ( dep1> 0 && dep2> 0 ) { $gnbM.children("ul").children("li").eq(dep1-1).addClass("active").children(".gnb-2dep").show().children("li").eq(dep2-1).addClass("on"); $gnbM.children("ul").children("li").eq(dep1-1).find(".close-icon").hide(); $gnbM.children("ul").children("li").eq(dep1-1).find(".open-icon").show(); } // Scroll Bg $(window).on("scroll", function() { if ($(window).scrollTop() > 100) { $("#header-wrap").addClass("bg"); }else { $("#header-wrap").removeClass("bg"); } }); });