$(function ($) { $(window).on("resize", function (e) { if ($(window).width() >= 1025) { $("#header-menu").remove(); //settimeout(function() { //menu() //}, 50) }else{ //settimeout(function() { menumoblie() //}, 50) } }).trigger("resize"); //选中 /*$(".header-menu li").each(function(index) { $(this).attr("id", "m" + index); });*/ open_menu() }); function open_menu() { //移动端打开菜单导航 $("#open_menu").click(function(e) { if ($(this).hasclass("open_menu_on")) { $(this).removeclass("open_menu_on") $("#header-menu").removeclass("header-menu-show"); } else { $(this).addclass("open_menu_on") $("#header-menu").addclass("header-menu-show"); } }); //移动端打开菜单导航 end } // function menu() { // var window_width = $(window).width(); // var a = $(".header-menu") // var b = a.find("ul") // var c = b.find("li") // //导航总宽度 // var m_total_width = b.width(); // //栏目总数 // var m_num = c.length // //栏目宽度px // var m_li_width = m_total_width / m_num // //栏目宽度% // c.width(100 / m_num + "%"); // //判断是否有下拉 加上样式has-sub // $(".header-menu li").each(function(index) { // //鼠标经过一级栏目效果 // $(this).bind("mouseover",function(e) { // $(this).addclass("aon"); // //$(this).siblings().removeclass("aon"); // }); // $(this).bind("mouseleave",function(e) { // $(this).removeclass("aon"); // }); //$("#m"+mid).addclass("aon"); // // // var sub_num = $(this).find(".sub").length // if (sub_num > 0) { // $(this).addclass("has-sub"); // //不同环境判断 // var x = $(this) // var y = x.find(".sub") // var z = y.find(".sub-menu") // var r = z.find("dl") // //下拉背景不全 // if (a.hasclass("no-fullbground")) { // x.addclass("relative"); //相对li定位 // $("body").css("overflow-x", "hidden"); //防止滚动条出现 // y.width(window_width); // } // //横向 // if (a.hasclass("sub-horizontal")) { // var r_width = r.width() //二级导航各自宽度 // var r_height = r.height() //二级导航各自高度 // rigth_side = window_width - x.position().left - ((window_width - $(".header").width()) / 2) // left_side = x.position().left - ((window_width - $(".header").width()) / 2) + x.width() // //alert(rigth_side) // if (m_num - x.index() <= 3) { // if (r_width > rigth_side) { //二级导航总宽度比导航右侧宽度大的时候 // y.addclass("sub-right"); // //判断右侧宽度太大加上宽度 // // if (r_width > left_side) { // r.width(left_side).height(r_height) // // y.addclass("sub-right-txt-r"); // //} // // // } else { // y.addclass("sub-left"); // } // } else { // y.addclass("sub-left"); // r.width(rigth_side).height(r_height) // } // // // } // //横向end // //下拉背景不全end // //下拉全背景 // if (a.hasclass("fullbground")) { // y.width($(".header").width()); // //alert(r.width()) // var halfw=(window_width - $(".header").outerwidth()) / 2 // leftw = r.width() / 2 - (x.outerwidth() / 2) // left_side = x.position().left - halfw // rigth_side = window_width - x.position().left - halfw - x.outerwidth() // aa=window_width-$(".header-menu").position().left-$(".header-menu").width()//判断导航右边距离是否等于左右距离(等于右边有无其他模块挡着) // bb=window_width-x.position().left-halfw-x.outerwidth()//当前li在内容$(".header-menu")右边距离 // cc=x.position().left//当前li在内容$(".header-menu")左边距离 // dd=cc-halfw // //左边 // if (leftw > left_side) { // y.css({"left": -left_side}); // } else { // y.css({"left": -leftw}); // } // //左边 end // //右边 // if(aa==halfw){ // if(leftw> rigth_side) { // y.css({"left": "auto","right":-bb}); // }else{ // //左边 // if (leftw > left_side) { // y.css({"left": -left_side}); // } else { // y.css({"left": -leftw}); // } // //左边 end // } // }else{ // /**/ // if (m_num - x.index() <= 3) { // if (leftw > rigth_side) { // if (bb==0) { //导航菜单右边没有模块 // y.css({"left": "auto","right": -(rigth_side-halfw)}); // }else{ // y.css({"left": "auto","right": -rigth_side}); // } // } else { // y.css({ // "left": -leftw // }); // } // } // /**/ // } // //右边 end // y.width(r.width()); // // // x.addclass("relative"); //相对li定位 // x.bind("mouseover",function(e) { // $(".sub-menu-layer").height(z.outerheight()) // }); // x.bind("mouseleave",function(e) { // $(".sub-menu-layer").height(0) // }); // } // //下拉全背景end // //不同环境判断end // } // }); // if (a.hasclass("fullbground")) { // $(".sub-menu-layer").remove(); // a.append(""); // } // //下拉菜单显示 // $(".header-menu .has-sub").each(function() { // //下拉竖向图文 // if (a.hasclass("sub-vertical")) { // var s_halfw=(window_width - $(".header").outerwidth()) / 2 // var sub_width = $(this).find(".sub").outerwidth() // var leftw = window_width - $(this).position().left - s_halfw // //alert(leftw)*2 // if (sub_width > leftw) { // $(this).find(".sub").addclass("sub-position-right"); // } // var n = $(this).find(".sub-menu").attr("data-level"); // if (n > 0) { // var sub_width_n = $(this).find(".sub").outerwidth() * n // if (sub_width_n > leftw) { // $(this).find(".sub").addclass("sub-position-right"); // } // } // } // //下拉竖向图文 end // //多级 // $(this).find(".sub").find(".sub-menu").find("dl").find("dt").each(function() { // var n = $(this).find("dl").find("dt").length // if (n >= 1) { // //$(this).find("i").remove(); // $(this).addclass("sub-has-sub") //.append(""); // } // }); // $(".header-menu .sub-has-sub").hover(function() { // $(this).children("dl:first").show(); // $(this).addclass("aon"); // $(this).siblings().removeclass("aon"); // }, function() { // $(this).children("dl:first").hide(); // $(this).removeclass("aon"); // }); // /////////////////一级 // $(this).find(".sub").height("auto"); // var subh=$(this).find(".sub").outerheight() // $(this).find(".sub").height(0); // $(this).bind("mouseover",function(e) { // $(this).find(".sub").css({"top":"70px",height:subh}); // }); // $(this).bind("mouseleave",function(e) { // $(this).find(".sub").css({"top":"-600%",height:0}); // }); // //end // }); // //下拉菜单显示end // } function menumoblie() { var html = $(".header-menu").html() $("#header-menu").remove(); $(".header-menu").before("
" + html + "
"); $("#open_menu").removeclass("open_menu_on") $("#header-menu li").each(function() { $(this).attr("style", " ").removeclass("relative"); $(this).find(".sub").attr("style", " "); $(this).find(".sub dl").attr("style", " "); var sub_num = $(this).find(".sub-menu").length if (sub_num > 0) { $(this).addclass("has-sub"); } //多级 $(this).find(".sub").find(".sub-menu").find("dl").find("dt").each(function() { var n = $(this).find("dl").find("dt").length if (n >= 1) { $(this).find("i").remove(); $(this).addclass("sub-has-sub").append(""); } }); }); //一级菜单 $("#header-menu .has-sub em").bind("click", function() { if ($(this).parent().hasclass("clickon")) { $(this).parent().removeclass("clickon"); $(this).next(".sub").stop(true, true).slideup(); } else { $(this).parent().addclass("clickon"); $(this).next(".sub").stop(true, true).slidedown(); $(this).parent().siblings().find(".sub").stop(true, true).slideup(); $(this).parent().siblings().removeclass("clickon"); } }); //多级菜单 $("#header-menu .sub-has-sub i").bind("click", function() { if ($(this).parent().hasclass("clickon")) { $(this).parent().removeclass("clickon"); $(this).parent().children("dl:first").stop(true, true).slideup(); } else { $(this).parent().addclass("clickon"); $(this).parent().children("dl:first").stop(true, true).slidedown(); } }); } $(".topul ul li").hover(function(){ var i=$(this).index(); $(".ullist ul").eq(i).addclass("on"); })