(function($, plugin) { var data = {}, id = 1, etid = plugin + 'etid'; $.fn[plugin] = function(speed, group) { id++; group = group || this.data(etid) || id; speed = speed || 150; if (group === id) this.data(etid, group); this._hover = this.hover; this.hover = function(over, out) { over = over || $.noop; out = out || $.noop; this._hover(function(event) { var elem = this; cleartimeout(data[group]); data[group] = settimeout(function() { over.call(elem, event) }, speed) }, function(event) { var elem = this; cleartimeout(data[group]); data[group] = settimeout(function() { out.call(elem, event) }, speed) }); return this }; return this }; $.fn[plugin + 'pause'] = function() { cleartimeout(this.data(etid)); return this }; $[plugin] = { get: function() { return id++ }, pause: function(group) { cleartimeout(data[group]) } } })(jquery, 'mousedelay'); /* /*by wanhu 20201020 */ var whirmenu = { main: function(type, lang, selectid) { whirmenu.public(lang, selectid); whirmenu.menutype(type); }, public: function(lang, selectid) { $("#m" + selectid).addclass("aon"); //头部导航选中当前栏目 var _li = $("#menu li"); if (lang == 'cn') { var num = _li.length, w = 100 / num; _li.outerwidth(w + "%"); } //判断是否有下拉 _li.each(function() { var n = $(this).find("dt").length if (n >= 1) { $(this).addclass("has-sub"); } //改变选中 鼠标经过去掉当前栏目选中 $(this).hover(function() { $(this).addclass("aon").siblings().removeclass("aon"); }, function() { $(this).removeclass("aon"); $("#m" + selectid).addclass("aon"); }); }); //纵向多级 $(".has-sub .sub dt").each(function(){ var e=$(this).find(".hierarchy ol").length if(e >= 1){ $(this).addclass("has-multi"); } }); //三级 $(".hierarchy ol").each(function(){ var n=$(this).find("ol").length if(n>=1){ $(this).addclass("has-multi") } }) }, menutype: function(type) { $(function($) { $(window).on("resize", function() { if ($(window).width() > 1025) { whirmenu.pc(type); } else { whirmenu.wap(); } }).trigger("resize"); }); }, pc: function(type) { //纵向 if (type == "vertical") { $(".has-sub").mousedelay(false).hover(function() { $(this).find(".sub").slidedown(300); $(this).siblings().find(".sub").slideup(300); //判断下拉框内容宽度超出屏幕 var subw = $(this).find(".sub").outerwidth(), this_pleft = $(this).position().left + $(this).outerwidth(), ww = $(window).width(), right_w = ww - this_pleft //console.log(this_pleft,right_w) if (subw >= right_w) { var leftcss = subw - right_w $(this).find(".sub").css("left", -leftcss); } else { $(this).find(".sub").css("left", ""); } //判断下拉框内容宽度超出屏幕 end }, function() { $(this).find(".sub").slideup(300); }); $("#menu").mouseleave(function() { $(this).find(".sub").slideup(300); }); //多级显示隐藏 $(".has-multi").hover(function(){ $(this).find(".hierarchy").eq(0).show() $(this).siblings().find(".hierarchy").eq(0).hide() },function(){ $(this).find(".hierarchy").eq(0).hide() }); } //横向 if (type == "horizontal") { $(".has-sub").mousedelay(false).hover(function() { $(this).siblings().find(".sub").fadeout(500); $(this).find(".sub").fadein(500); var sumwidth = 0 $(this).find(".sub").find("dt").each(function() { sumwidth += $(this).width() //得到总宽度 }); var ww = $(window).width() var _half = sumwidth / 2 var _left = $(this).position().left + ($(this).outerwidth() / 2) var _endleft = _left - _half if(sumwidth < ww){ //是否下拉宽度大于window宽度 $(this).find(".sub").find("dl").css("margin-left", _endleft) //判断右侧宽度是否等于或者大于下拉宽度的一半 if($("#menu").parents(".auto").length==1){ //判断内容宽度 左右留白 var _halfww=(ww-$("#menu").parents(".auto").outerwidth())/2 var _endright = _halfww var rightw=ww-_left-_halfww } else{ var rightw=ww-_left var _endright = 0//rightw/2 - ($(this).outerwidth() / 2) } if(_half > rightw){ $(this).find(".sub").find("dl").removeattr("style").css({"margin-right": _endright,"float":"right"}) } //判断右侧宽度是否等于或者大于下拉宽度的一半 end } }, function() { $(this).find(".sub").fadeout(300); }) } //左侧竖向菜单 子菜单竖排 if (type == 'leftvertical') { $(".has-sub").mousedelay(false).hover(function() { $(this).find(".sub").fadein(300); $(this).siblings().find(".sub").hide(); var th = $(this).offset().top - $(document).scrolltop(); var wh = $(window).height() var dlh = $(this).find(".sub dl").height() //判断越近底部高度减少 栏目高度超出 if (th + dlh > wh) { $(this).find(".sub dl").css("padding-top", th - (th + dlh - wh)) } else { $(this).find(".sub dl").css("padding-top", th) } }, function() { $(this).find(".sub").fadeout(300); $(this).find(".sub dl").removeattr("style"); }); } }, wap: function() { $("#menu li,#menu,.has-multi").unbind(); $(".has-sub .op,.has-multi .op-multi").remove(); $(".has-sub").find("span").append(""); $(".has-multi > aside").append(""); //打开二级 $('.op').click(function() { $(this).toggleclass("click"); $(this).parent().next(".sub").slidetoggle(); $(this).parent().parent().siblings().find(".op").removeclass("click"); $(this).parent().parent().siblings().find(".sub").slideup(); }); //打开多级 $('.op-multi').click(function() { $(this).toggleclass("click"); $(this).parent().next(".hierarchy").slidetoggle(); $(this).parent().parent().siblings().find(".op-multi").removeclass("click"); $(this).parent().parent().siblings().find(".hierarchy").slideup(); }); //打开移动端导航 $(".open-menu").unbind(); whiropen.one(".open-menu", "body", "menu-show", "#menu"); //end } } var whiropen = { one: function(a, b, bclass, c) { $(a).click(function(e) { $(this).toggleclass("on"); $(b).toggleclass(bclass); $(document).on("click", function() { $(b).removeclass(bclass); $(a).removeclass("on"); }); e.stoppropagation(); }); $(c).on("click", function(e) { e.stoppropagation(); }); }, toggle: function(a, b) { $(a).click(function(e) { $(this).toggleclass("on"); $(b).stop(true, true).slidetoggle(); $(document).on("click", function() { $(b).stop(true, true).slideup(); $(a).removeclass("on"); }); e.stoppropagation(); }); $(b).on("click", function(e) { e.stoppropagation(); }); }, hover: function(a, b) { $(a).hover(function() { $(b).stop(true, true).slidetoggle(); $(this).toggleclass("on") }); $(a).mouseleave(function() { $(b).slideup(); $(a).removeclass("on") }); } } var whirsearch = { open: function(a, b) { $(a).click(function(e) { $(this).toggleclass("on"); $(b).stop(true, true).fadetoggle(); $(document).on("click", function() { $(b).stop(true, true).fadeout(); $(a).removeclass("on"); }); e.stoppropagation(); }); $(b).on("click", function(e) { e.stoppropagation(); }); }, search: function(a, b, c, d) { $(a).jqsearch({ txtval: c, keytxt1: "输入关键词搜索!", keytxt2: "输入的关键词字数不要过多!", keytxt3: "您输入的内容存在特殊字符!", keyid: b, //输入框id keyurl: d, //跳转链接 keyhref: "key", //链接传值 static: false //是否静态站 }); }, searchen: function(a, b, c, d) { $(a).jqsearch({ txtval: c, keytxt1: "enter keywords to search!", keytxt2: "do not enter too many keywords!", keytxt3: "there are special characters in the content you entered!", keyid: b, //输入框id keyurl: d, //跳转链接 keyhref: "key", //链接传值 static: false //是否静态站 }); } }