//banner function banner(obj1){ var obj1=obj1;//传入参数 var obj=new object; obj.nowindex=0;//banner切换的序号 obj.interval="";//banner切换计时器 obj.banner=obj1.banner;//banner框架 obj.btn=obj1.btn;//banner按钮框架 obj.btnurl=obj1.btnurl;//按钮路径 obj.bool=obj1.bool||true;//判断切换 obj.btnurlon=obj1.btnurlon;//;按钮被点击路径 obj.selnum=obj1.selnum; obj.allnum=obj1.allnum; obj.getmun=function(){//获取banner个数 var mun=$(obj.banner).length-1; return mun; } obj.mun=0;//banner个数 //添加按钮 obj.btnappend=function(){ $(obj.banner).not($(obj.banner+":eq(0)")).stop(false,true).hide(); $(obj.banner+":eq(0)").show(); $(obj.banner+":eq(0) .contentinfo").show(); $(obj.allnum).text(obj.mun+1); $(obj.btn).append("
"); for(var i=1;i<=obj.mun;i++){ $(this.btn).append(""); } } //确定哪个为白色 obj.btnposition=function(btnindex){ $(obj.selnum).text(btnindex+1); $(obj.btn+" .bannernavchild").removeclass("on"); $(obj.btn+" .bannernavchild:eq("+btnindex+")").addclass("on"); } //切换事件 obj.bannerdo=function(btnindex){ $(obj.banner+":eq("+obj.nowindex+") .contentinfo").stop(true,true).hide(); $(obj.banner+":eq("+obj.nowindex+")").stop(true,true).delay(600).fadeout(500); if(btnindex||btnindex==0){ obj.nowindex=btnindex; }else{ obj.nowindex==obj.mun?obj.nowindex=0:obj.nowindex++; } obj.btnposition(obj.nowindex); $(obj.banner+":eq("+obj.nowindex+")").stop(true,true).delay(600).fadein(500); $(obj.banner+":eq("+obj.nowindex+") .contentinfo").stop(true,true).show(); } return obj; } // banner over var banner1=new banner({ banner:".banner .contents .content", btn:".bannernav", btnurl:"/images/index/bannerbtn.jpg", btnurlon:"/images/index/bannerbtnon.jpg", selnum:"#selnum", allnum:"#allnum" }); //白点被点击 function bannerbtnclick(btnindex){ //alert("a"); if(btnindex=="-"){ banner1.nowindex==0?btnindex=banner1.mun:btnindex=banner1.nowindex-1; }else if(btnindex=="+"){ banner1.nowindex==banner1.mun?btnindex=0:btnindex=banner1.nowindex+1; } clearinterval(banner1.interval); banner1.bannerdo(btnindex); banner1.btnposition(btnindex); banner1.interval=setinterval(function(){ banner1.bannerdo(null); },5000); } function btn2click(btnindex){ if(btnindex=="-"){ banner1.nowindex==0?btnindex=banner1.mun:btnindex=banner1.nowindex-1; }else if(btnindex=="+"){ banner1.nowindex==banner1.mun?btnindex=0:btnindex=banner1.nowindex+1; } clearinterval(banner1.interval); banner1.bannerdo(btnindex); banner1.btnposition(btnindex); banner1.interval=setinterval(function(){ banner1.bannerdo(null); },5000); } $(function(){ /*banner*/ banner1.mun=banner1.getmun(); banner1.btnappend(); banner1.interval=setinterval(function(){ banner1.bannerdo(null); },5000); //$(".banner").mouseover(function(){ // $(".bannerleft").show(); // $(".bannerright").show(); // }); // $(".banner").mouseout(function(){ // $(".bannerleft").hide(); // $(".bannerright").hide(); // }); });