//index.js JavaScript Document var $ = jQuery; var isMobile = true, keepMobile = false; var window_Width = $(window).width(); var window_Height = $(window).height(); $(window).resize(function () { //监听浏览器尺寸变化 window_Width = $(window).width(); window_Height = $(window).height(); IfIsMobile(); }); function IfIsMobile() { //if (getCookie("bohoog_mobile_state") != 'false') { if (getCookie("bohoog_mobile_state") == 'true') { window_Width <= 600 ? isMobile = true : isMobile = false; }else{ isMobile = false; } //console.log(isMobile); } //GetQueryString方法 function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return (r[2]); return null; } function getCookie(name) { var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)) return unescape(arr[2]); else return null; } function setCookie_mobile(objName, objValue) { var str = objName + "=" + escape(objValue); str += "; path=/;"; document.cookie = str; } if (GetQueryString("isMobile") && GetQueryString("isMobile") != '') { setCookie_mobile("bohoog_mobile_state", GetQueryString("isMobile")); } IfIsMobile(); $(function () { if (!isMobile) { // 如果是非适配模式,移除适配css文件 $("link[name='mobile']").remove(); } if(isMobile){ $(".nav_menu .item").each(function() { if($(this).children("dl").length > 0){ $(this).children("h1").append(''); } }) $(".nav_menu .item>h1 i").click(function() { let _dl = $(this).parent().next("dl"); if(_dl.hasClass("open")){ _dl.slideUp(200); _dl.removeClass("open"); $(this).removeClass("open"); }else{ _dl.slideDown(200); _dl.addClass("open"); $(this).addClass("open"); } }) $(".header.zsjyc .nav_menu #NavUl>li,.header.dwjsgzb .nav_menu #NavUl>li,.header.tsxx .nav_menu #NavUl>li").each(function() { if($(this).children(".bmNavDrop").length > 0){ $(this).children("a").after(''); } }) $(".header.zsjyc .nav_menu #NavUl>li>i,.header.dwjsgzb .nav_menu #NavUl>li>i,.header.tsxx .nav_menu #NavUl>li>i").click(function() { let _dl = $(this).next(".bmNavDrop"); if(_dl.hasClass("open")){ _dl.slideUp(200); _dl.removeClass("open"); $(this).removeClass("open"); }else{ _dl.slideDown(200); _dl.addClass("open"); $(this).addClass("open"); } }) } }); //用于计算导航宽度 function calcUlWidth(demo){ var _calcUlWidth = 0; $(demo).children().each(function(){ if($(this).hasClass("on")){ $(demo).attr("scrollL", _calcUlWidth); } _calcUlWidth += $(this).outerWidth(true); }); $(demo).width(_calcUlWidth+5); $(demo).parent().scrollLeft($(demo).attr("scrollL")); }