$(document).ready(function () { //ajax请求 function _ajax(url,type,data,callback){ $.ajax({ url:url, type:type, data:data, success: function (data) { callback(data); }, // async:false, }); } $("#mb-header #navbar-main #search-ico").on("click",function(){ $("#mb-header #navbar-main #search-container").toggle() }) function changeURLArg(url, arg, arg_val) { var pattern = arg + "=([^&]*)"; var replaceText = arg + "=" + arg_val; if (url.match(pattern)) { var tmp = "/(" + arg + "=)([^&]*)/gi"; tmp = url.replace(eval(tmp), replaceText); return tmp; } else { if (url.match("[?]")) { return url + "&" + replaceText; } else { return url + "?" + replaceText; } } } $(".show-num .menu .item").on("click", function () { var url = window.location.href; var page_size = $(this).attr("data-value"); if (window.location.search == "") { window.location.href = url + "?page_size=" + page_size; } else { window.location.href = changeURLArg(url, "page_size", page_size); } }); function throttle(fun, delay, ele) { let last, deferTimer; return function (args) { let that = this; let _args = arguments; let now = +new Date(); if (last && now < last + delay) { clearTimeout(deferTimer); deferTimer = setTimeout(function () { last = now; fun.apply(that, _args); }, delay); } else { last = now; fun.apply(that, _args); } }; } function ajax() { var val = $("header #pc-header .search-form .search-inp > input").val(); if (val !== "") { $( "header #pc-header .search-form .search-inp .hint-search-content" ).show(); $.each( $(".search-form .search-inp .hint-search-content .item"), function () { $(this).find(".i-list").html(""); } ); $.ajax({ url: "/apiv2/search", data: { name: val, }, success: function (res) { var arr = JSON.parse(res); var course = arr.data.course; var program = arr.data.program; if (course.length == 0) { $( ".search-form .search-inp .hint-search-content .course-item > div" ).append( `undefined...` ); } else { course.forEach((val) => { $( ".search-form .search-inp .hint-search-content .course-item > div" ).append(` ${val.goods_name} ${val.ke_college} `); }); } if (program.length == 0) { $( ".search-form .search-inp .hint-search-content .program-item > div" ).append( `undefined...` ); } else { program.forEach((val) => { $( ".search-form .search-inp .hint-search-content .program-item > div" ).append(` ${val.goods_name} ${val.ke_college} `); }); } console.log(JSON.parse(res)); }, }); } else { $( "header #pc-header .search-form .search-inp .hint-search-content" ).hide(); } } function ajax1() { var val = $(".list-banner .search-con1 .inp > input").val(); if (val !== "") { $(".list-banner .search-con1 .inp .hint-search-content").show(); $.each( $(".list-banner .search-con1 .inp .hint-search-content .item"), function () { $(this).find(".i-list").html(""); } ); $.ajax({ url: "/apiv2/search", data: { name: val, }, success: function (res) { var arr = JSON.parse(res); var course = arr.data.course; var program = arr.data.program; if (course.length == 0) { $( ".list-banner .search-con1 .inp .hint-search-content .course-item > div" ).append( `undefined...` ); } else { course.forEach((val) => { $( ".list-banner .search-con1 .inp .hint-search-content .course-item > div" ).append(` ${val.goods_name} ${val.ke_college} `); }); } if (program.length == 0) { $( ".list-banner .search-con1 .inp .hint-search-content .program-item > div" ).append( `undefined...` ); } else { //${val.url} program.forEach((val) => { $( ".list-banner .search-con1 .inp .hint-search-content .program-item > div" ).append(` ${val.goods_name} ${val.ke_college} `); }); } console.log(JSON.parse(res)); }, }); } else { $(".list-banner .search-con1 .inp .hint-search-content").hide(); } } function ajax2() { var val = $("#mb-header #navbar-main #search-container > input").val(); if (val !== "") { $( "#mb-header #navbar-main #search-container .hint-search-content" ).show(); $.each( $("#mb-header #navbar-main #search-container .hint-search-content .item"), function () { $(this).find(".i-list").html(""); } ); $.ajax({ url: "/apiv2/search", data: { name: val, }, success: function (res) { var arr = JSON.parse(res); var course = arr.data.course; var program = arr.data.program; if (course.length == 0) { $( "#mb-header #navbar-main #search-container .hint-search-content .course-item > div" ).append( `undefined...` ); } else { course.forEach((val) => { $( "#mb-header #navbar-main #search-container .hint-search-content .course-item > div" ).append(` ${val.goods_name} ${val.ke_college} `); }); } if (program.length == 0) { $( "#mb-header #navbar-main #search-container .hint-search-content .program-item > div" ).append( `undefined...` ); } else { program.forEach((val) => { $( "#mb-header #navbar-main #search-container .hint-search-content .program-item > div" ).append(` ${val.goods_name} ${val.ke_college} `); }); } console.log(JSON.parse(res)); }, }); } else { $( "#mb-header #navbar-main #search-container .hint-search-content" ).hide(); } } function ajax3() { var val = $(".list-banner .search-con .inp > input").val(); if (val !== "") { $(".list-banner .search-con .inp .hint-search-content").show(); $.each( $(".list-banner .search-con .inp .hint-search-content .item"), function () { $(this).find(".i-list").html(""); } ); $.ajax({ url: "/apiv2/search", data: { name: val, }, success: function (res) { var arr = JSON.parse(res); var course = arr.data.course; var program = arr.data.program; if (course.length == 0) { $( ".list-banner .search-con .inp .hint-search-content .course-item > div" ).append( `undefined...` ); } else { course.forEach((val) => { $( ".list-banner .search-con .inp .hint-search-content .course-item > div" ).append(` ${val.goods_name} ${val.ke_college} `); }); } if (program.length == 0) { $( ".list-banner .search-con .inp .hint-search-content .program-item > div" ).append( `undefined...` ); } else { program.forEach((val) => { $( ".list-banner .search-con .inp .hint-search-content .program-item > div" ).append(` ${val.goods_name} ${val.ke_college} `); }); } console.log(JSON.parse(res)); }, }); } else { $(".list-banner .search-con .inp .hint-search-content").hide(); } } $("header #pc-header .search-form .search-inp > input").bind( "input propertychange", throttle(ajax, 2000) ); $(".list-banner .search-con1 .inp input").bind( "input propertychange", throttle(ajax1, 2000) ); $(".list-banner .search-con .inp input").bind( "input propertychange", throttle(ajax3, 2000) ); $("#mb-header #navbar-main #search-container > input").bind( "input propertychange", throttle(ajax2, 2000) ); $(document).on("click", function (e) { if (!$(e.target).is(".search-inp,.search-inp *")) { $( "header #pc-header .search-form .search-inp .hint-search-content" ).hide(); } }); // 搜索跳转 $("body").on("click",".homesearch",function () { var name = $('.homeinputval').val(); window.location.href="/brand?keyword="+name }) function GetQueryString(name) { var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if(r!=null)return unescape(r[2]); return null; } var secret = GetQueryString("keyword"); $(".homeinputval").val(secret); // var pathname = window.location.pathname; // if (pathname.indexOf("/brand") != -1) { // $("header #pc-header ul li").removeClass("active"); // $("header #pc-header ul li").eq(1).addClass("active"); // } // var pathname = window.location.pathname; // if (pathname.indexOf("/program") != -1) { // $("header #pc-header ul li").removeClass("active"); // $("header #pc-header ul li").eq(2).addClass("active"); // } $("a[href*=#]").click(function () { var h = $("#pc-head").innerHeight(); $("html, body").animate( { scrollTop: $($(this).attr("href")).offset().top - h + "px" }, 500 ); return false; }); function hideCookie() { $("footer .cookie").css({ transform: "translateY(" + $("footer .cookie").innerHeight() + "px)", }); $("body").css({ paddingBottom: 0, }); } function showCookie() { $("footer .cookie").css({ transform: "translateY(0)", }); $("body").css({ paddingBottom: $("footer .cookie").innerHeight() + "px", }); } if ($.cookie("the_cookie") == "the_time") { hideCookie(); } else { showCookie(); } $("footer .cookie .container a").click(function () { $.cookie("the_cookie", "the_time", { expires: 1, path: "/" }); hideCookie(); }); $(".container-mask").on("click", function (e) { e = window.event || e; var obj = e.srcElement || e.target; if ($(obj).is(".container-mask .container,.container-mask .container *")) { if ($(obj).is(".close-iconf")) { $(this).removeClass("show"); } else { $(this).addClass("show"); } } else { $(this).removeClass("show"); } }); if ($(window).width() > 768) { $("body").css({ paddingBottom: $("#apply").innerHeight() + "px", }); $(window).scroll(function () { if ($(this).scrollTop() >= $("header").innerHeight()) { $("header").addClass("fixed"); } else { $("header").removeClass("fixed"); } }); } //移动端导航初始化 var $mainSidebar = $("#sidebar-main"); var navbarHeight = $("#navbar-main").innerHeight(); $mainSidebar.simplerSidebar({ // align:'left', attr: "sidebar-main", top: navbarHeight, right: 1300, selectors: { trigger: "#sidebar-main-trigger", quitter: ".quitter", }, animation: { easing: "easeOutQuint", }, }); // 返回顶部 $(".go-top").click(function () { function clickHandler() { var currentScroll = document.documentElement.scrollTop || document.body.scrollTop; if (currentScroll > 0) { window.requestAnimationFrame(clickHandler); window.scrollTo(0, currentScroll - currentScroll / 6); } } clickHandler(); }); // 执行加载动画 if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))){ var wow = new WOW({ boxClass: 'wow', /* 执行动画的元素 class */ animateClass: 'animated', /* animate.css 动画的 class */ offset: 10, /* 距离可视区域多少开始执行动画 */ mobile: true, /* 是否在移动设备执行动画 */ live: true /* 异步加载的内容是否有效 */ }); wow.init(); }; });