// Custom scrollbar class var scrollBar = new Class ({ initialize: function(content,scrollbar,handle,horizontal,ignoreMouse) { this.content = $(content); this.scrollbar = $(scrollbar); this.handle = $(handle); this.steps = (horizontal?(this.content.getSize().scrollSize.x - this.content.getSize().size.x):(this.content.getSize().scrollSize.y - this.content.getSize().size.y)); if ((this.content.getSize().scrollSize.y - this.content.getSize().size.y) <= 0) { this.scrollbar.setStyle('display', 'none'); } this.slider = new Slider(this.scrollbar, this.handle, { steps: this.steps, mode: (horizontal?'horizontal':'vertical'), onChange: function(step){ // Scrolls the content element in x or y direction. var x = (horizontal?step:0); var y = (horizontal?0:step); // this.content not defined this.content.scrollTo(x,y); }.bind(this) }).set(0); if( !(ignoreMouse) ){ //scroll content when within the content div this.content.addEvent('mousewheel', function(e){ e = new Event(e).stop(); var step = this.slider.step - (e.wheel * 30); this.slider.set(step); }.bind(this)); // scroll the content when using the handle scrubber this.scrollbar.addEvent('mousewheel', function(e){ e = new Event(e).stop(); var step = this.slider.step - (e.wheel * 30); this.slider.set(step); }.bind(this)); } // Stops the handle dragging process when the mouse leaves the document body. $(document.body).addEvent('mouseleave',function(){this.slider.drag.stop()}.bind(this)); } });