// javascript document /*js类构造函数*/ function themoveclass(classname,thewidth,theshowcount){ this.leftobj = $("#"+classname+" .next").get(0); //左边按钮 this.rightobj = $("#"+classname+" .prev").get(0); //右边按钮 this.imglist = $("#"+classname+" .list").get(0); //图片列表大盒子 this.imgullist = $("#"+classname+" .list ul").get(0); //列表ul节点 this.imgli = $("#"+classname+" .list ul li"); this.imgcount = $("#"+classname+" .list ul li").length; //图片个数 this.index = 0; //判断当前在第几个 this.thespeed = 5000; //速度(用于定时执行) this.thetimeer = null; //定时器 this.thefangxiang = "left"; //默认方向 this.thewidth = thewidth; //滚动宽度 this.theshowcount = theshowcount; //显示个数 } //初始化方法 themoveclass.prototype.init=function(){ var themaxwidth = this.imgcount * this.thewidth; $(this.imgullist).css({"width":themaxwidth+"px"}); //设置ul宽度 this.bindevt(); //调用绑定事件 this.autoplay(); //调用自动播放 } //绑定事件 themoveclass.prototype.bindevt=function(){ var theobj = this; $(this.leftobj).click(function(){ //点击左边按钮 if(theobj.thetimeer!=null){ clearinterval(theobj.thetimeer); //清空定时器 } theobj.thefangxiang="right"; //设置方向 theobj.showone(); //显示图片 theobj.autoplay(); //设置定时器 }) $(this.rightobj).click(function(){ //点击右边按钮 if(theobj.thetimeer!=null){ clearinterval(theobj.thetimeer); //清空定时器 } theobj.thefangxiang="left"; //设置方向 theobj.showone(); //加载图片 theobj.autoplay(); //设置定时器 }) $(this.imgli).hover(function(){ clearinterval(theobj.thetimeer); //清空定时器 },function(){ theobj.autoplay(); //设置定时器 }) } //自动滚动 themoveclass.prototype.autoplay=function(){ var theobj = this; this.thetimeer = setinterval(function(){ //设置定时器 theobj.showone(); //加载图片 },this.thespeed) } //滚动显示一个 themoveclass.prototype.showone=function(){ var theobj = this; if(this.thefangxiang=="left"){ //判断移动方向 //this.thewidth; $(this.imgullist).animate({"margin-left":-theobj.thewidth},500,function(){ $(theobj.imgullist).css({"margin-left":"0px"}).find("li:first").appendto($(theobj.imgullist)); }); //设置滚动自定义动画 }else{ $(theobj.imgullist).css({"margin-left":-theobj.thewidth}).prepend($(theobj.imgullist).find("li:last")); $(this.imgullist).animate({"margin-left":"0px"},500,function(){ }); //设置滚动自定义动画 } }