//written by nathan faubion: http://n-son.com //use this or edit how you want, just give me //some credit! function jsscroller (o, w, h) { var self = this; var list = o.getelementsbytagname("div"); for (var i = 0; i < list.length; i++) { if (list[i].classname.indexof("scroller-container") > -1) { o = list[i]; } } //private methods this._setpos = function (x, y) { if (x < this.viewablewidth - this.totalwidth) x = this.viewablewidth - this.totalwidth; if (x > 0) x = 0; if (y < this.viewableheight - this.totalheight) y = this.viewableheight - this.totalheight; if (y > 0) y = 0; this._x = x; this._y = y; with (o.style) { left = this._x +"px"; top = this._y +"px"; } }; //public methods this.reset = function () { this.content = o; this.totalheight = o.offsetheight; this.totalwidth = o.offsetwidth; this._x = 0; this._y = 0; with (o.style) { left = "0px"; top = "0px"; } }; this.scrollby = function (x, y) { this._setpos(this._x + x, this._y + y); }; this.scrollto = function (x, y) { this._setpos(-x, -y); }; this.stopscroll = function () { if (this.scrolltimer) window.clearinterval(this.scrolltimer); }; this.startscroll = function (x, y) { this.stopscroll(); this.scrolltimer = window.setinterval( function(){ self.scrollby(x, y); }, 40 ); }; this.swapcontent = function (c, w, h) { o = c; var list = o.getelementsbytagname("div"); for (var i = 0; i < list.length; i++) { if (list[i].classname.indexof("scroller-container") > -1) { o = list[i]; } } if (w) this.viewablewidth = w; if (h) this.viewableheight = h; this.reset(); }; //variables this.content = o; this.viewablewidth = w; this.viewableheight = h; this.totalwidth = o.offsetwidth; this.totalheight = o.offsetheight; this.scrolltimer = null; this.reset(); };