(function($){ $.fn.nav=function(option){ var _this=$(this), cont=_this.next(), img=cont.find("img"), timer, n, timer_h, index, defaults={scale:1.2}, opts=$.extend({},defaults,option); // 初始化二级导航位置 cont.css("top",_this.offset().top+_this.outerheight()+"px"); //初始化二级导航栏目大小 cont.find("a").width(opts.width).height(opts.height); _this.on("mouseenter","a",function(){ var that=$(this); //导航栏目下小背景条动画 console.log("//导航栏目下小背景条动画") var wd=document.documentelement.clientwidth; that.find("."+opts.line).stop().animate({width:"100%",left:0,opacity:1},200) that.siblings().removeclass("c").find("."+opts.line+":not(."+opts.linesel+")").stop().animate({width:0,left:"50%",opacity:0},200) n=0; if(that.attr(opts.expattr)){//判断是否有二级菜单 cleartimeout(timer); console.log("判断是否有二级菜单") var wd=document.documentelement.clientwidth; cont.stop().animate({height:opts.height+100+"px",width:wd,marginleft:-_this.offset().left},200); if(!that.hasclass("c")){ index=_this.find("a["+opts.expattr+"]").index(this); cont.children().eq(index).show().siblings().hide() menuinit()//二级菜单初始化 sn(cont.children().eq(index)) that.addclass("c") } }else{ timer=settimeout(function(){ cont.stop().animate({height:0},200) menuinit() },200) } }) _this.parent().on("mouseleave",function(){//鼠标离开整个导航区 console.log("鼠标离开整个导航区") _this.find("."+opts.line+":not(."+opts.linesel+")").stop().animate({width:0,left:"50%"},200) cont.stop().animate({height:0},200) menuinit() _this.find("a").removeclass("c") }) img.each(function(){//二级菜单图片鼠标滑过效果 console.log("二级菜单图片鼠标滑过效果") $(this).parent().hover(function(){ $(this).stop().animate({width:opts.width*1.2+"px",height:opts.height*1.2+"px",left:-0.1*opts.width+"px",top:-0.1*opts.height,opacity:0.3},400) },function(){ $(this).stop().animate({width:opts.width+"px",height:opts.height+"px",left:0,top:0,opacity:1},400) }) }) function menuinit(){//初始化二级菜单 console.log("初始化二级菜单") img.each(function(){ $(this).parent().css({width:0,height:0,left:"50%",top:"50%"}) $(this).parent().siblings().hide() }) } function sn(obj){//二级菜单逐个显示 console.log("二级菜单逐个显示") obj.find("img").eq(n).parent().animate({width:opts.width+"px",height:opts.height+"px",left:0,top:0},40,function(){ obj.find("img").eq(n).parent().next().show() n+=1 if(n