$().ready(function () { // currentNavBox 当前over的元素 let currentNavBox = undefined; // nav父元素事件 $(".header_logo_nav") .find(".nav_box") .find("li") .mouseover(function () { currentNavBox = $(this); // 先隐藏所有的子元素,再把当前父元素对应的子元素显示 $(this).parents(".header_logo_nav").find(".submenubox").hide(); $(this).find(".submenubox").show(); }) .mouseleave(function () { // 当前的元素和之前over的元素一致时,不隐藏子元素 if (currentNavBox !== undefined && currentNavBox.is($(this))) { return; } $(this).find(".submenubox").hide(); currentNavBox = undefined; }); // nav子元素隐藏 $(".header_logo_nav") .find(".submenubox") .mouseleave(function () { $(this).hide(); }); // 搜索框 $('.searchIcon').click(function(){ if($(this).prev().css("width") == '0px'){ $(this).prev().animate({'width':'200px'}); }else{ $(this).prev().animate({'width':'0px'}); } }); //左侧分类点击 $('.page_left').find('.father_btn').click(function () { $(this).next(".child_box").toggle(); }); $('.page_left').find(".child_box").find(".child_btn").click(function () { $(this).next(".grandson_box").toggle(); }); //if (window.matchMedia("(max-width: 102px)").matches) { // console.log("这是一个移动设备。"); //} else { // console.log("这是平板电脑或台式电脑。"); //} //移动端导航高亮 var urlS = window.location.pathname; console.log(urlS) if (urlS == "/") { $('.phone_footer_nav').find('a:nth-child(1)').addClass("active"); } }); window.onscroll = function(){ if ($(document).width() > 1024 && $(document).height() > 1500) { if($(document).scrollTop() >= 50){ $('.search_box').hide(); $('.header_nav_box').addClass("header_nav_fixed"); }else{ $('.search_box').show(); $('.header_nav_box').removeClass("header_nav_fixed") } } } window.onresize = function () { if ($(document).width() > 1024 && $(document).height() > 1500) { if ($(document).scrollTop() >= 50) { $('.search_box').hide(); $('.header_nav_box').addClass("header_nav_fixed"); } else { $('.search_box').show(); $('.header_nav_box').removeClass("header_nav_fixed") } } } function pageScroll(){ window.scrollBy(0,-100); scrolldelay = setTimeout('pageScroll()',0); var sTop=document.documentElement.scrollTop+document.body.scrollTop; if(sTop==0) clearTimeout(scrolldelay); }