function change(){ var o={}; return o={ data:{ "lastindex":0, //上一个序号,默认为0 "index":0, //当前序号,默认为0 "mun":0, //数量总数 "autoplay":false, //是否开启自动切换 "autoplay_time":3000, //自动切换时间差 "autoplay_interval":"", //自动切换计时器 "autoplay_settimeout":null,//暂停计时器 "autoplay_settimeout_time":3000,//暂停时间 "btn_function":"",//切换事件方法 "btn_element":"", //切换按钮父类对象 "btn_select":"on", //切换按钮选中按钮的class "btn":"", //切换按钮html "parent_move_element":"", //移动的父类框 "parent_element":"", //最大父类框 "element":"", //最小的对象 "position_style":"order", //order 顺序 loop 循环 no 不定位只隐藏 "position_width":null, //定位的宽度 }, init:function(data){ //赛选初始化数据 $.each(data,function(i,n){ o.data[i]=data[i]; }); //确定数量 if(!this.data["mun"])this.data["mun"]=$(this.data["element"]).length-1; //确定宽度 if(!this.data["position_width"])this.data["position_width"]=$(this.data["element"]).width(); //判读是否启动切换 if(this.data["autoplay"])this.autoplay(); //定点 this.position(); }, //清除切换 remove:function(){ clearinterval(this.data["autoplay_interval"]); cleartimeout(this.data["autoplay_settimeout"]); }, //定点 position:function(){ //移动内容定点 if(this.data["position_style"]=="no"){ $(this.data["element"]).hide(); $(this.data["element"]+":eq("+this.data["index"]+")").show(); }else if(this.data["position_style"]=="loop"){ $(this.data["element"]).css({"left":-this.data["position_width"]+"px"}); $(this.data["element"]+":eq("+this.data["index"]+")").css({"left":"0px"}); }else if(this.data["position_style"]=="order"){ $.each($(this.data["element"]),function(i,n){ $(n).css({"left":i*o.data["position_width"]+"px"}); }); $(this.data["parent_move_element"]).css({"left":this.data["index"]*this.data["position_width"]+"px"}); } //按钮定位 if(this.data["btn"]){this.btn_position();} }, //按钮初始化 btn_position:function(){ for(var i=0;i<=this.data["mun"];i++){ $(this.data["btn_element"]).append(this.data["btn"]); $(this.data["btn_element"]).children().eq(i).attr("onclick",this.data["btn_function"]+".todo({'index':"+i+"})"); } $(this.data["btn_element"]).children().eq(this.data["index"]).addclass(this.data["btn_select"]); }, //按钮切换 btn_todo:function(data){ var index=!isnan(data["index"])?data["index"]:this.data["index"]; $(this.data["btn_element"]).children().removeclass(this.data["btn_select"]); $(this.data["btn_element"]).children().eq(index).addclass(this.data["btn_select"]); }, //重置定时器 autoplay:function(){ clearinterval(this.data["autoplay_interval"]); cleartimeout(this.data["autoplay_settimeout"]); this.data["autoplay_settimeout"]=settimeout(function(o){ o.data["autoplay_interval"]=setinterval(function(o){o.todo(o);},o.data["autoplay_time"],o); },this.data["autoplay_settimeout_time"],this); }, //切换 todo:function(data){ //判断是否传入配置 if(data["data"])this.data=data["data"]; //设置上一个切换的序号 if((!isnan(data["index"])||data["direc"])&&this.data["autoplay"])this.autoplay(); this.data["lastindex"]=this.data["index"]; //判断当前序号 if(!isnan(data["index"])){this.data["index"]=data["index"];}else{ if(data["direc"]=="-"){ if(this.data["autoplay"])this.autoplay(); this.data["index"]==0?this.data["index"]=this.data["mun"]:this.data["index"]--; }else if(data["direc"]=="+"){ if(this.data["autoplay"])this.autoplay(); this.data["index"]==this.data["mun"]?this.data["index"]=0:this.data["index"]++; }else{ this.data["index"]==this.data["mun"]?this.data["index"]=0:this.data["index"]++; } } if(this.data["position_style"]=="no"){ $(this.data["element"]+":eq("+this.data["lastindex"]+")").stop(false,true).fadeout(500); $(this.data["element"]+":eq("+this.data["index"]+")").stop(false,true).fadein(500); }else if(this.data["position_style"]=="loop"){ var direc=-1; if(data["direc"]=="-")direc=1; $(this.data["element"]+":eq("+this.data["lastindex"]+")").stop(false,true).animate({"left":direc*this.data["position_width"]+"px"},500); $(this.data["element"]+":eq("+this.data["index"]+")").stop(false,true).css({"left":-direc*this.data["position_width"]+"px"}).animate({"left":"0px"},500); }else if(this.data["position_style"]=="order"){ $(this.data["parent_move_element"]).stop(false,true).animate({"left":-this.data["index"]*this.data["position_width"]+"px"},500); } //按钮选中切换 if(this.data["btn"]){ this.btn_todo({});} }, } }