MooTools Content Slider Class

So I’ve been wanting to write a class like this for a while now and I finally got around to it. It creates a content slider. That being said a content slider could be a number of things these days but, this particular one creates a slider that manipulates the position of the content in a div element. The class constructor takes three arguments and can be called using:

Usage


new ContentSlider(element, sliderTrack, sliderKnob, options);

Parameters

The element parameter needs to be an element that is wrapped within a viewport div. The viewport div’s width will be what is seen. While the element div’s width will be set using Javascript. In order for this to happen your item_list li element needs to have a set width. While the getSize() method of MooTools works dynamically in Firefox it only counts set properties in Safari and Internet Explorer. Dear MooTools Team, if it is possible please fix this.

The sliderTrack parameter is the background of the slider. The track if you will. It will wrap around the sliderKnob.

The sliderKnob parameter is the actual knob of the slider. The knob or controller needs to have a set width or else it won’t work in Safari or IE.

The option for itemList is very important as well. It takes an ID of an element and is absolutely necessary. By default it looks for a ul tag with and id of ‘item_list’.

Important thing about this class is it absolutely requires that your HTML markup is properly set up. While something with this many variants is difficult to write a blueprint for, I tried anyway. Reason for this is I have seen this done a lot, mostly in jQuery. I wanted to show that the same effect could be done in a reusable manner with minimal code. I hope someone out there is able to use this.

jQuery Users

For those of you who are looking to accomplish this effect in jQuery check this out.

Demo and Download

You can see it in action here.
Download a zip here.

Popular Posts

Help The Javascript Blog

If you would like to write for The Javascript Blog or submit a plugin or class please feel free to contact us.


One Response

08.09.09

I like mootools

Leave Your Response

* Name, Email, Comment are Required