I’ve been developing a portal site using ruby on rails and script.aculo.us and I wanted to be able to scroll the contents of some of the ‘portlets’ but I wanted the scrollbars to match the overall appearance of the page, which the standard scrollbars don’t. I’d seen this done before so I assumed that script.aculo.us would have implemented such a thing, but they hadn’t. I managed to find some examples of scrollable div javascript libraries on the net of which the best are probably fleXcroll and the scrolling layer content page at dyn-web, but I had a couple of concerns like: Would they work if the content were updated via Ajax? Would they live in harmony with script.aculo.us?
So in the end I decided to implement my own (I seem to live my life saying to myself; ‘how hard could it be’?). This is the result. It is certainly not as accomplished as fleXcroll, but it works fine if content is updated using Ajax and it re-uses scipt.aculo.us classes so its pretty small and is guaranteed to play nice with it too. (BTW – its based pretty heavily on this one. I couldn’t see any licensing terms, but credit where credit is due).
If you use Ajax to re-write the original div you will need to make sure it has an id and then call Scroller.reset(
The appearance of the scrollbar can be controlled using a stylesheet. The scrollbar itself has class scroll-track, the thumb (the part you grab) has class scroll-handle. This is the stylesheet I use at the portal above:
.scroll-track{
height:10px;
width:10px;
background:black;
}
.scroll-handle{
border: 1px solid black;
height:10px;
width:10px;
background:#5B207B;
cursor:pointer;
}
Obviously you could set the classes to use images as the background too if you wanted – which is what the examples on this page do.
Demo: http://www.jools.net/projects/javascript/scrollable-divs/
Download: http://jools.net/wsvn/Projects/trunk/scroller/scroller.js
Source: http://www.jools.net/projects/javascript/scrollable-divs/

Related Listings:
RSS feed for comments on this post. TrackBack URL
October 28th, 2009 at 2:45 am
[...] Custom Scrollbars Script I’ve been developing a portal site using ruby on rails… [...]