function scrollbox(box) { this.box = $("#" + box); this.name = "li左右滚动类"; this.author = "keboy"; this.version = "v1.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.css("overflow","hidden").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); } ); } } };