$(function () { if ('scrollRestoration' in history) { history.scrollRestoration = 'manual'; } var winW = $(window).width(); var winH = $(window).height(); var conW = $("footer").width() - 90; var SboxScrollT = []; var timeOff = 1; var search = location.search; var loc; var navLis; var HW = { init: function () { loc = this.formatSearch(search); var flag = false; if (loc.section) { flag = true; } if (winW > 1200) { navLis = $("#pc-nav"); } else { navLis = $("#wap-nav"); } if (flag) { flag = false; setTimeout(function () { navLis.find("li[data-key='" + loc.section + "']").trigger("click"); }, 200) } }, scrollHead: function () { var scrollT = $(document).scrollTop(); if (scrollT > 0) { $("#all-container").addClass("min"); } else { $("#all-container").removeClass("min"); } }, boxScrollT: function () { SboxScrollT = []; $(".anchorpoint").each(function () { SboxScrollT.push($(this).offset().top); }); }, scrollFastNav: function () { var that = this; if (timeOff) { timeOff = 0; var timer = setTimeout(function () { HW.boxScrollT(); var scrollT = $(document).scrollTop() + 80; for (var i = 0; i < SboxScrollT.length; i++) { if (i == SboxScrollT.length - 1) { if (SboxScrollT[i] < scrollT) { $(".pc-nav li").eq(i).addClass("current").siblings().removeClass("current"); $(".menue-wrap li").eq(i).addClass("current").siblings().removeClass("current"); } } else { if (SboxScrollT[i] < scrollT && scrollT < SboxScrollT[i + 1]) { $(".pc-nav li").eq(i).addClass("current").siblings().removeClass("current"); $(".menue-wrap li").eq(i).addClass("current").siblings().removeClass("current"); } } } timeOff = 1; }, 500); } }, fastNav: function () { $(this) .addClass("current") .siblings() .removeClass("current"); var charClass = "anchorpoint" + $(this).index(); if ($("." + charClass).offset()) { var $scrollT = $("." + charClass).offset().top - 50; } $("html,body").animate({ scrollTop: $scrollT }); }, wapNav: function () { var wap_navbtn = $(".wap_navbtn"), wap_nav = $("#wap-nav"); $(".wap_navbtn,#wap-nav").on("click", function () { if (!$(this).hasClass("close")) { wap_navbtn.addClass("close"); wap_nav.addClass("close"); wap_nav.animate({ top: "0%" }); $("#wap-nav > div").css("display", "block"); } else { wap_navbtn.removeClass("close"); wap_nav.removeClass("close"); wap_nav.animate({ top: "-100%" }); $("#wap-nav > div").css("display", "none"); } }); }, dblclick: function () { if (winW < 1200) { document.documentElement.addEventListener("dblclick", function (e) { e.preventDefault(); }); } }, setContactW: function () { winW = $(window).width(); if (winW > 768) { $(".footer-box").width("auto"); var contactW = 0, num = 0, conW = $(".footer-box").outerWidth(); $(".js_contact_us ul").each(function () { $(this).width("auto"); var W = $(this).outerWidth(true); contactW += $(this).outerWidth(true); W > num ? (num = W) : num; }); if (contactW > conW) { $(".footer-box").width(num + 10); $(".contact-us ul").width(num + 10); contactW = 0; } else { $(".footer-box").width(contactW + 10); num = 0; } } else { $(".footer-box").width("auto"); $(".contact-us ul").width("auto"); } }, backTop: function () { //返回顶部 $(".js_back_top").click(function () { $("html,body").animate({ scrollTop: 0 }); }); $(window).scroll(function () { var htmlScrollT = $(document).scrollTop(); if (htmlScrollT > 100) { $(".js_back_top").fadeIn(); } else { $(".js_back_top").fadeOut(); } }); }, setBgAndPosition: function () { var num = 0, index = 0; $(".anchorpoint").each(function () { if (!$(this).hasClass("none")) { $(this).addClass("anchorpoint" + index + ""); } index++; }); }, setBlockCenter: function (Object) { var obj = $(Object); obj.each(function () { var len = $(this).find("li").length; if (len == 1) { $(this).addClass("col-1"); } else if (len == 2) { $(this).addClass("col-2"); } else if (len == 3) { $(this).addClass("col-3"); } else if (len == 4) { $(this).addClass("col-4"); } else if (len == 5) { $(this).addClass("col-5"); } else if (len == 6) { $(this).addClass("col-6"); } }); }, setHeight: function (obj, obj2, num) { var This = $(obj), oList = This.find(obj2); if (winW > num) { This.each(function () { var _this = $(this), oList = _this.find(obj2), oList_len = oList.length, oBox_w = _this.outerWidth(true), oList_w = oList.width(), oColumn_len = Math.floor(oBox_w / oList_w), oRow_len = Math.ceil(oList_len / oColumn_len), oList_H = 0, oList_obj = null; oList.height("auto"); for (var i = 0; i < oRow_len; i++) { for (var j = i * oColumn_len; j < oColumn_len * (i + 1); j++) { oList.eq(j).addClass("oList_obj"); var H = oList.eq(j).height(); H > oList_H ? (oList_H = H) : oList_H; oList_obj = $(".oList_obj"); } oList_obj.height(oList_H).removeClass("oList_obj"); oList_H = 0; } }); } else { oList.height("auto"); } }, setHeight2: function (obj, obj2) { var obj = $(obj), obj2 = $(obj2); obj2.height(obj.height()); }, setHeight3: function (obj) { var This = $(obj); var oList_len = This.length, oList_H = 0; This.height("auto"); for (var i = 0; i < oList_len; i++) { var H = This.eq(i).height(); H > oList_H ? (oList_H = H) : oList_H; This.height(oList_H); } }, loc: { section: undefined, // speech: undefined }, GetQueryString: function (name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var str = window.location.search.substr(1).match(reg); if (str != null) return unescape(str[2]); return null; }, formatSearch: function (se) { if (typeof se !== "undefined" && se !== "") { se = se.substr(1); var arr = se.split("&"), obj = this.loc || {}, newarr = []; $.each(arr, function (i, v) { newarr = v.split("="); if (typeof obj[newarr[0]] === "undefined") { obj[newarr[0]] = newarr[1]; } }); return obj; } else { return this.loc; } }, rep: function (obj, o, n) { var reg, res; reg = new RegExp("(\\?|&)" + o + "=[^&]*", "ig"); res = obj.replace(reg, "$1" + o + "=" + n); if (!reg.test(obj)) { res += (search ? "&" : "?") + o + "=" + n; } return res; }, replaceUrl: function (url) { if (history.pushState && url && location.href.replace([location.protocol, location.host].join("//")) != url) { history.pushState({ title: document.title }, document.title, [location.protocol, location.host].join("//") + url); } } }; //获取每一个块的高度 HW.boxScrollT(); // HW.wapNav(); HW.dblclick(); HW.setBgAndPosition(); //设置anchorpoint索引 HW.setContactW(); //设置底部footer宽度自适应 $(window).off('resize.header').on('resize.header', function () { var windowW = $(window).width(); if (windowW != winW) { //获取每一个块的高度 HW.boxScrollT(); winW = windowW; HW.setContactW(); //设置底部footer宽度自适应 HW.init(); } }); //顶部滚动时改变高度 // if(winW > 992){ $(window).bind("scroll", HW.scrollHead); $(window, "document").scrollTop(0); // } //pc端,导航定位 $("#pc-nav li").bind("click", HW.fastNav); //wap端,导航定位 $("#wap-nav li").bind("click", HW.fastNav); //加载条 $(".loader").fadeOut(); HW.init(); /** * 功能:空校验 */ function checkCookieEmpty(value) { value = $.trim(value); return ( value != null && value != "undefined" && value != "" && value != '""' && value != "null" ); } $(window).scroll(function () { HW.scrollHead() HW.scrollFastNav(); }); function menueWrap() { if (winW <= 1200) { var flag = false; var wrapLis = $(".menue-wrap").find("li"); wrapLis.on("click", function () { $(this).addClass("current") $(this).siblings().removeClass("current"); if (flag) { $(".wap_navbtn").removeClass("close"); $(".menue-wrap").slideUp(); $('body').css('overflow', 'auto'); } else { $(".wap_navbtn").addClass("close"); $(".menue-wrap").slideDown(); $('body').css('overflow', 'hidden'); } flag = !flag; }); $(".wap_navbtn").on("click", function () { var wHeight = $(window).height(); if (flag) { $(this).removeClass("close"); $(".menue-wrap").slideUp(); $('body').css('overflow', 'auto'); if ($('.menue-wrap .worldwide .bg').hasClass('active')) { $('.menue-wrap .worldwide .bg').removeClass('active'); $('.menue-wrap .worldwide .worldwide-con').animate({ 'height': '0' }) } } else { $(this).addClass("close"); $(".menue-wrap").slideDown(); $('body').css('overflow', 'hidden'); } flag = !flag; }) // 点击worilwide按钮时,显示语种 $('.menue-wrap .worldwide .bg').on('click', function () { if ($(this).hasClass('active')) { $(this).removeClass('active'); $('.menue-wrap .worldwide .worldwide-con').animate({ 'height': '0' }) } else { $(this).addClass('active'); $('.menue-wrap .worldwide .worldwide-con').animate({ 'height': '100%' }) } }) } else { // 如果头部展开,js关闭它 if ($('#wap-nav').css('display') == 'block') { $('#wap-nav').css('display', 'none'); } } } setTimeout(function () { menueWrap(); }, 200) // 自适应 var winw = $(window).width(); var resizeTimer = null; $(window).off('resize.menueWrap').on('resize.menueWrap', function () { var curWin_w = $(window).width(); if (winw != curWin_w) { clearTimeout(resizeTimer) resizeTimer = setTimeout(function () { menueWrap(); winw = curWin_w; }, 100); }; }) // 检测定期内是否有text $('.header .header-con .cistern .pc_navbtn #pc-nav .clearfix li a').each(function () { if (!$(this).text()) { $(this).parent().fadeOut(); } }); $('header .header-con .cistern .pc_navbtn .pc-nav > ul > li.pull-down').hover(function() { var ulHei = $(this).find('ul').height(); $(this).find('.pull').height(ulHei); }, function() { $(this).find('.pull').height(0); }); // banner slide2 按钮点击跳转 $('.ebg-module-swiper-banner-two .swiper-slide .text .ebg-btn-box .maodian').on('click', function() { var dataKey = $(this).attr('data-key'); navLis.find("li[data-key='" + dataKey + "']").trigger("click"); $('header .header-con .cistern .wap_btn .wap_navbtn').removeClass('close'); $('.menue-wrap').hide(); $('body').css('overflow', 'auto'); flag = false; }); });