//判断访问终端 var browser = { versions: function(){ var u = navigator.useragent, app = navigator.appversion; return { trident: u.indexof('trident') > -1, //ie内核 webkit: u.indexof('applewebkit') > -1, //苹果、谷歌内核 mobile: !!u.match(/applewebkit.*mobile.*/), //是否为移动终端 android: u.indexof('android') > -1 || u.indexof('adr') > -1, //android终端 ipad: u.indexof('ipad') > -1, //是否ipad weixin: u.indexof('micromessenger') > -1, //是否微信 (2015-01-22新增) }; }(), language:(navigator.browserlanguage || navigator.language).tolowercase() } $(".header .search-box").mouseleave(function (e) { var e = e || event; $(".search-dot").css({ transform: "rotate(180deg)" }); }); // 顶部tab var taglist = new swiper(".com-tag-list", { slidesperview: "auto", freemode: true, watchslidesprogress: true, }); /* 初始化页面com-tag-list元素 @param targetparentel 需要添加锚点元素列表的父元素 */ function initcomtaglist(targetparentel) { var pathname = window.location.pathname var $headerel = $(".header"); if(pathname.indexof("invest") != -1 || pathname.indexof("project") != -1) { return; } $(".com-tag-list .com-tag-item").click(function () { var index = $(this).parent().index(); var targetel = $(targetparentel).children().eq(index); var offsettop = targetel.offset().top; $("html").animate( { scrolltop: offsettop - $headerel.outerheight() + 3 }, 600 ); }); } initcomtaglist(".target-content"); initdata(); function initdata() { var $fixtop = $(".fixed-el"); // 占位符 避免 页面闪烁 $fixtop.each(function () { var tit = $(this)[0]; //占位符的位置 var rect = tit.getboundingclientrect(); // 获得页面中导航条相对于浏览器视窗的位置 var inser = document.createelement("div"); tit.parentnode.replacechild(inser, tit); inser.appendchild(tit); inser.style.height = rect.height + "px"; }); } // 处理header函数 function handleheaderscroll() { var pathname = window.location.pathname var $fixtop = $(".fixed-el"); var scrolltop = $("html").scrolltop(); // header元素 var $headerel = $(".header"); var $headerheight = $(".header").outerheight(); // 公共banner元素 var $combannerel = $(".com-banner"); var $headerlogo = $(".header .header-logo .header-logo-pic"); if (scrolltop > 0) { $headerel.css({height: "5.5em"}) } if (scrolltop === 0){ $headerel.attr("style", "") } if( (pathname.indexof("project") != -1 && pathname .split("/").length <= 4) || pathname.indexof("search") != -1 // pathname.indexof("school/2") != -1 || // pathname.indexof("school/1") != -1 ) { $headerel.addclass("deep deep-black"); $headerlogo.attr("src", $headerlogo.attr("data-black")); return; } if ($combannerel.length < 1) { $headerel.addclass("deep deep-black"); $headerlogo.attr("src", $headerlogo.attr("data-black")); return; } // console.log($headerel.outerheight()); // console.log(scrolltop); // console.log($combannerel.height()); // 头部元素即将超出banner 时 增加对应class // if ($headerel.outerheight() + scrolltop > $combannerel.height()) { if (scrolltop > 0) { $headerel.addclass("deep deep-black"); $headerlogo.attr("src", $headerlogo.attr("data-black")); } else { $headerel.removeclass("deep deep-black"); $headerlogo.attr("src", $headerlogo.attr("data-white")); } if(!browser.versions.weixin) { $fixtop.each(function (index, dom) { var beforeoffsettop = dom.offsettop; if(!pathname.indexof("abouts") != -1) { if ($(dom).parent()[0].offsettop - scrolltop <= $headerheight) { $(dom).addclass("fixed"); $(dom).css("top", $headerheight); } else { $(dom).removeclass("fixed"); } } if (beforeoffsettop >= scrolltop) { $(dom).removeclass("fixed"); } }); } } /* 节流函数 @param fn function @param wait number @param maxtimelong number @return function */ function throttling(fn, wait, maxtimelong) { var timeout = null, starttime = date.parse(new date()); return function () { if (timeout !== null) cleartimeout(timeout); var curtime = date.parse(new date()); if (curtime - starttime >= maxtimelong) { fn(); starttime = curtime; } else { timeout = settimeout(fn, wait); } }; } window.addeventlistener("scroll", throttling(handleheaderscroll, 200, 600)); handleheaderscroll(); // wow 动画 new wow().init(); // 移动端导航 function mobilenavevent() { var whitelogoarr = [0, 2, 5]; var pathname = window.location.pathname // 公共banner元素 var $headerel = $(".header"); var $headerlogo = $(".header .header-logo .header-logo-pic"); var usemobilebtn = $(".mo-nav"); var usemobilenav = $(".navs-mo"); var usemobileitem = $(".navs-mo .list .li"); // 是否是白色导航 var iswhite = !$headerel.hasclass("deep deep-black"); // || !pathname.indexof("abouts") != -1 usemobilebtn.click(function () { // 首页 if(pathname === '/') { // 关闭二级菜单 if ($(this).hasclass("open")) { $(this).removeclass("open"); usemobilenav.removeclass("open"); var activeindex = $("#currentswiper").val(); if (whitelogoarr.indexof(+activeindex) > -1) { $headerel.removeclass("deep deep-black"); $headerel.attr("style", "") $headerlogo.attr("src", $headerlogo.attr("data-white")); } else { console.log('not') } } // 打开二级菜单 else { $(this).addclass("open"); usemobilenav.addclass("open"); $headerel.addclass("deep deep-black"); $headerlogo.attr("src", $headerlogo.attr("data-black")); } } // 非首页 else { var scrolltop = $("html").scrolltop(); // 透明顶部导航 if( pathname.indexof("abouts") != -1 || pathname.indexof("business") != -1 || pathname.split('/').length > 4 || pathname.indexof("news") != -1 || pathname.indexof("jobs") != -1 || pathname.indexof("school") != -1 ) { if(scrolltop > 0) { console.log('透明离开顶部') if (!$(this).hasclass("open")) { $(this).addclass("open"); usemobilenav.addclass("open"); } else { $(this).removeclass("open"); usemobilenav.removeclass("open"); } } else { console.log('透明顶部') if (!$(this).hasclass("open")) { $(this).addclass("open"); usemobilenav.addclass("open"); $headerel.addclass("deep deep-black"); $headerlogo.attr("src", $headerlogo.attr("data-black")); } else { $(this).removeclass("open"); usemobilenav.removeclass("open"); $headerel.removeclass("deep deep-black"); $headerel.attr("style", "") $headerlogo.attr("src", $headerlogo.attr("data-white")); } } } // 非透明顶部导航 else { if (!$(this).hasclass("open")) { $(this).addclass("open"); usemobilenav.addclass("open"); } else { $(this).removeclass("open"); usemobilenav.removeclass("open"); } } } }); usemobileitem.click(function () { if($(this).hasclass('active')) { $(this).removeclass("active"); } else { $(this).addclass("active").siblings().removeclass("active"); } }); } mobilenavevent(); // 二维码弹窗 var useqrcodepopup = $(".public--qrcode-popup"); var useopenqrcodepopup = $(".js-open-qrcode") var usecloseqrcodepopup = $(".js-close-qrcode") useopenqrcodepopup.click(function () { useqrcodepopup.slidedown(500) }) usecloseqrcodepopup.click(function () { useqrcodepopup.slideup(500) }) // 初始化 head 搜索 var usewindowwidth = $(window).width(); function initheadsearchevent () { var headnav = $(".header .header-nav"); var searchbox = $(".header .search-box"); var searchbtn = $(".header .search-box .search-wrap"); var searchinput = $(".head-search"); var closesearchboxbtn = $(".header .search-box .head-search .icon-close"); searchbtn.click(function (event) { if(searchbox.hasclass("open")) { // 搜索内容 window.location = "/search/1/?keyword=" + $("#headkey").val() } else { if(usewindowwidth > 1025) { headnav.hide(); searchbox.addclass("open"); searchinput.show(300); } else { $(".header .search-box .head-search input").css("width", "7em"); searchbox.addclass("open"); searchinput.show(300); $(".mo-nav").hide(); } } }); closesearchboxbtn.click(function (event) { $("#headkey").val("") if(usewindowwidth > 1025) { searchbox.removeclass("open"); headnav.attr("style", "") searchinput.hide(300); } else { searchbox.removeclass("open"); searchinput.hide(300); $(".mo-nav").attr("style", "") } }) } window.addeventlistener("resize", function () { usewindowwidth = $(window).width(); throttling(initheadsearchevent, 600, 1000) }); initheadsearchevent(); $("#headkey").keydown(function (event) { if(event.keycode == 13) { window.location = "/search/1/?keyword=" + $("#headkey").val() } })