$(function() { /** 全部分类显示隐藏 */ var num; var hideTimer = null; function clearHideTimer(){ if(hideTimer){ clearTimeout(hideTimer); hideTimer = null; } } $('.header_nav>li[id]').hover(function() { clearHideTimer(); var Obj = $(this).attr('id'); num = Obj.substring(3, Obj.length); catehoveradd(); if($('#box-' + num).has('.menudrop_con').length){ $('#box-' + num).find(".menudrop_left li:first-child").addClass('selected').siblings().removeClass('selected'); var $con = $('#box-' + num).find(".menudrop_con"); $con.find(".menudrop_tab").css("opacity", 0); $con.find(".menu_three").css("opacity", 0); $con.find(".menudrop_tab li:first-child").addClass('selected').siblings().removeClass('selected'); $con.find(".menudrop_tab:first-child").show().siblings(".menudrop_tab").hide(); $con.find(".menu_three:first-child").show().siblings(".menu_three").hide(); $con.find(".menu_three ul:first-child").show().siblings(".menu_three ul").hide(); if($con.find(".menudrop_left li:first-child").parents(".menudrop_con").find(".menudrop_tab:first-child").find("li").length==0){//判断是否有二级菜单 $con.find(".menudrop_left").css("border","none"); }else{ $con.find(".menudrop_left").css("border-right","1px solid #dedede"); } if($con.find(".menu_three:first-child").find("li").length==0){//判断是否有三级菜单 $con.find(".menudrop_right").css("border","none"); }else{ $con.find(".menudrop_right").css("border-left","1px solid #dedede"); } $con.find(".menudrop_center").css("transform","translateX(0px)"); setTimeout(function(){ $con.find(".menudrop_tab:first-child").css("opacity", 1); $con.find(".menu_three:first-child").css("opacity", 1); }, 200); } }, function() { hideTimer = setTimeout(catehoverremove, 150); }); function catehoveradd(){ // 先移除所有 box 的 open 类,避免多个下拉面板同时显示导致内容不刷新 $('.header-menu-list').removeClass("open"); $('#box-' + num).addClass("open"); // 高亮当前触发的导航项,让用户知道下拉内容属于哪个栏目 $('.header_nav>li>a').removeClass('nav-hover'); $('#li-' + num + '>a').addClass('nav-hover'); $("body").addClass("showing"); $('#header_menu_drop').css("height",$('#box-' + num).height()); $('#box-' + num).find(".h-menu-list2 dl").css("height",$('#box-' + num).height()); var len = $('#box-' + num).find(".h-menu-list2 dl").length; $('#box-' + num).find(".h-menu-list2 dl:first-child").css("margin-left", (5-len)+"0%"); } function catehoverremove(){ $('#box-' + num).removeClass("open"); $('.header_nav>li>a').removeClass('nav-hover'); $("body").removeClass("showing"); $('#header_menu_drop').removeAttr("style"); $('#box-' + num).find(".h-menu-list2 dl").removeAttr("style"); $('#box-' + num).find(".menudrop_tab, .menu_three").css("opacity", 0); } $('.header-menu-list').hover(function() { clearHideTimer(); catehoveradd(); $('#box-' + num).find(".menudrop_left li:first-child").parents(".menudrop_con").find(".menudrop_center").css("transform","translateX(0px)"); }, function() { hideTimer = setTimeout(catehoverremove, 150); }); $('.menudrop_left li').hover(function(){//下拉菜单一级 // 如果划过的是当前已选中栏目,跳过淡入动画,避免重复动态效果 if($(this).hasClass('selected')){ return; } $(this).parents(".menudrop_con").find(".menudrop_center").addClass("menu_animate"); var i=$(this).index(); $(this).addClass('selected').siblings().removeClass('selected'); if($(this).parents(".menudrop_con").find(".menudrop_tab").eq(i).find("li").length==0){ $(this).parents(".menudrop_con").find(".menudrop_left").css("border","none"); }else{ $(this).parents(".menudrop_con").find(".menudrop_left").css("border-right","1px solid #dedede"); } if($(this).parents(".menudrop_con").find(".menu_three").eq(i).find("li").length==0){ $(this).parents(".menudrop_con").find(".menudrop_right").css("border","none"); }else{ $(this).parents(".menudrop_con").find(".menudrop_right").css("border-left","1px solid #dedede"); } var $con = $(this).parents(".menudrop_con"); $con.find(".menudrop_tab").css("opacity", 0); $con.find(".menu_three").css("opacity", 0); $con.find(".menudrop_tab").eq(i).show().siblings(".menudrop_tab").hide(); $con.find(".menu_three").eq(i).show().siblings(".menu_three").hide(); $con.find(".menu_three ul:first-child").show().siblings(".menu_three ul").hide(); setTimeout(function(){ $con.find(".menudrop_tab").eq(i).css("opacity", 1); $con.find(".menu_three").eq(i).css("opacity", 1); }, 20); $con.find(".menudrop_tab li:first-child").addClass('selected').siblings().removeClass('selected'); }, function() { $(this).parents(".menudrop_con").find(".menudrop_center").removeClass("menu_animate"); }) $('.menudrop_tab li').hover(function(){//下拉菜单二级 // 如果划过的是当前已选中栏目,跳过淡入动画,避免重复动态效果 if($(this).hasClass('selected')){ return; } $(this).parents(".menudrop_con").find(".menu_three").addClass("menu_animate"); var i=$(this).index(); var i2=$(this).parent().index(); if($(this).parents(".menudrop_con").find(".menu_three").eq(i2).find("ul").eq(i).find("li").length==0){ $(this).parents(".menudrop_con").find(".menudrop_right").css("border","none"); }else{ $(this).parents(".menudrop_con").find(".menudrop_right").css("border-left","1px solid #dedede"); } $(this).addClass('selected').siblings().removeClass('selected'); var $three = $(this).parents(".menudrop_con").find(".menu_three").eq(i2); $three.find("ul").css("opacity", 0); $three.find("ul").eq(i).show().siblings(".menu_three ul").hide(); setTimeout(function(){ $three.find("ul").eq(i).css("opacity", 1); }, 20); }, function() { $(this).parents(".menudrop_con").find(".menu_three").removeClass("menu_animate"); }) /** 返回顶部 */ $(window).scroll(function() { var pos = Math.max($("html").scrollTop(), $("body").scrollTop()); if (pos > 100) { $(".returnTop").show() } else { $(".returnTop").hide() } }); $(".returnTop").click(function() { $("html").animate({ scrollTop : 0 }, 1000); $("body").animate({ scrollTop : 0 }, 1000) }) $(".search_tb").click(function(){ $(this).find(".header_serch").toggle(); }) $('.header_serch').click(function(){ $(this).show(); return false; }); layui.use('layer',function(){ layui.jquery(".footer_con").on("click","[data-way='3']",function(){ var src = $(this).data('con'); layer.photos({ anim: 5, photos: { opacity: 0.3, data: [ { src: src } ], success: function(){ } }, }); return; layui.layer.open({ type : 1, title : false, closeBtn : 0, skin : 'layui-layer-nobg', shadeClose : true, content : $('.preview-code-img') }); }) }) function headerStyle() { if ($('.main-header').length) { var windowpos = $(window).scrollTop(); var siteHeader = $('.main-header'); if (windowpos >= 200) { siteHeader.addClass('fixed-header'); } else { siteHeader.removeClass('fixed-header'); } if(windowpos>0&&windowpos<200){ $("body").removeClass("showing"); } } } function navStyle() { if($('.main_nav').length){/*导航栏固定到头部*/ var windowpos = $(window).scrollTop(); var siteHeader = $('.main_nav'); if (windowpos >= 100) { siteHeader.addClass('fixed_nav'); } else { siteHeader.removeClass('fixed_nav'); } } } if($('.main_nav .nav_right').length){ navStyle(); $(window).bind('scroll', function() {navStyle();}); }else{ headerStyle();$(window).bind('scroll', function() {headerStyle();}); } $("#submit,#submit1").bind("click",function(){ var prev = $(this).data('prev'); var val = $(this).prev("input").val(); if(val != ''){ if(prev){ location.href = prev + '/search/'+val+'.html'; }else{ location.href = '/search/'+val+'.html'; } } return false; }) })