$().ready( function() { var box = new scrollbox("scrollbox"); //参数为滚动容器的id,容器必须具备overflow:hidden属性,容器下必须具备标签格式为。 box.clientwidth = 650; //显示窗口区域宽度。 box.step = 1; //滚动步长。 box.speed = 30; //滚动每步长执行时间(毫秒)。 box.space = 30; //如果使用margin做图片间隔,在此设置间隔距离。 box.forward = "left"; //滚动初始方向。向左滚动,值为“left”,向右滚动,值为“right”。 box.norecord = "
本栏目暂无资料,感谢您的关注...
"; //暂无记录时插入页面的html代码。 box.control = true; //是否可以控制滚动方向。是为true,否为false。 box.ctrlclass = "ctrl"; //定义方向控制按钮的属性class。左右两个按钮设置为相同的class,并且页面中不能再次出现这个class。 box.ctrlspeed = 10; //定义方向控制按钮按下时的速度加倍倍数。 box.stop = true; //鼠标悬停时,是否停止。是为true,否为false。 box.default(); //初始化。初始化完成后将自动开始滚动。 } ); function scrollbox(box) { this.box = $("#" + box); this.name = "li左右滚动类"; this.author = "keboy"; this.version = "1.0"; this.createdate = "2009-12-15"; } scrollbox.prototype = { clientwidth: 0, space: 0, step: 0, defstep: 0, speed: 0, forward: "", norecord: "", control: false, ctrlclass: "", stop: true, defaulthtml: "", defaulti: 1, gocross: 0, ctrlspeed: 0, default: function() { var _this = this; this.defaulthtml = this.box.find("ul:first").html(); this.defstep = this.step; this.box.find("li").each( function() { _this.gocross += ( $(this).get(0).offsetwidth + _this.space ); } ); this.setdefault(); }, setdefault: function() { var _this = this; var li = this.box.find("li"); if ( li.length > 0 ) { var liwidth = 0; li.each( function() { liwidth += ( $(this).get(0).offsetwidth + _this.space ); } ); if ( liwidth >= 2 * this.clientwidth ) { var endhtml = this.box.find("ul:first").html(); endhtml += endhtml; this.box.find("ul:first").html(endhtml).css("width",liwidth * 2 + "px"); this.start(); } else { var newhtml = ""; for ( var i = 0 ; i < this.defaulti ; i++ ) { newhtml += this.defaulthtml; } this.defaulti++; this.box.find("ul:first").html(newhtml); this.setdefault(); } } else { this.box.find("ul:first").html(this.norecord); } }, start: function() { var _this = this; var mar = setinterval(getscroll,this.speed); function getscroll() { if ( _this.forward == "left" ) { if ( _this.box.get(0).scrollleft > _this.gocross ) { _this.box.get(0).scrollleft -= _this.gocross; } else { _this.box.get(0).scrollleft += _this.step; } } else if ( _this.forward == "right" ) { if ( _this.box.get(0).scrollleft <= 0 ) { _this.box.get(0).scrollleft += _this.gocross; } else { _this.box.get(0).scrollleft -= _this.step; } } } if ( this.control ) { $("." + this.ctrlclass).css("cursor","pointer"); $("." + this.ctrlclass + ":first").mouseover( function() { _this.forward = "left"; } ).mousedown( function() { _this.step = _this.defstep * _this.ctrlspeed; } ); $("." + this.ctrlclass + ":last").mouseover( function() { _this.forward = "right"; } ).mousedown( function() { _this.step = _this.defstep * _this.ctrlspeed; } ); $(document).mouseup( function() { _this.step = _this.defstep; } ); } if ( this.stop ) { this.box.mouseover( function() { clearinterval(mar); } ).mouseout( function() { mar = setinterval(getscroll,_this.speed); } ); } } };