You will recieve your password to this address. Address is not made public.

Your preferred username that is used when logging in.

jQuery Tools / Scrollable - Scroll your HTML with eye candy

Forget about scrollbars

Flying screens

The purpose of this library is to make it extremely easy to add scrolling functionality to a website. Whenever you wish to scroll HTML elements in a visually-appealing manner, this is the only library you need. The main design goals of this library are to provide visual customization functionality and programmability. Here are some example scenarios where you would benefit from using the library:

  • Home pages, like this one right here
  • Product catalogues
  • News tickers
  • Custom select boxes in forms
  • Image galleries
  • Video playlists
  • All kinds of navigational systems

The first version of the library was released on January 3, 2008. Since then, this tool has come a long way and it is now a stable and mature product.


Rich yet simple

  • Horizontal and vertical scrolling.
  • Scrolling using navigational buttons, API calls, keyboard arrow keys, and the mouse scroll wheel.
  • The number of items scrolled at once is customizable.
  • The navigational buttons are setup without a single line of JavaScript.
  • Tabbed navigation like this one can be setup without any programming.
  • Programmatic actions are available, such as: next, prev, nextPage, prevPage, seekTo, begin, and end.
  • Dynamic addition and removal of Scrollable items.
  • The ability to customize the scrolling experience with onBeforeSeek and onSeek listeners.

This tool uses a simple and natural syntax and has an advanced programming API. You can extend it with callback methods or with your own plugins. This tool has a similar structure and feel as the other tools. Learn to use this tool and you will know how to use the rest.

This tool is a mature project and is actively maintained. The source code is clean, professional and easy to follow. It passes Douglas Crockford's JavaScript Verifier and it it doesn't assign any global variables. Active forums keep this tool alive and you can expect to see new releases coming out in the future.

Extendable architecture

Just like other tools this tool can be extended with plugins. Currently available plugins include:

  • circular   makes an infinite loop from the Scrollable items so they continue cycling back to the beginning once the last item is reached.
  • autoscroll   makes the scrolling behaviour automatic and is highly configurable.
  • navigator   provides navigation buttons for switching between pages in Scrollable.
  • mousewheel   enables mousewheel support for Scrollable.

You can also write your own plugins. Another way to alter the default behaviour is the ability to make your own animation effects. There is lots of room for experimentation!

Look at the first demo to get started

You can study the workings of Scrollable in the following examples. They contain documented source code, along with a standalone page to allow you to easily transfer the examples to your own site. The most important example is the first one, "Minimal setup for Scrollable" because it teaches you the basics of using the library.

Besides clicking on the tabs you can also scroll through the elements:

  1. Clicking on the content area
  2. Clicking on the action buttons below the scrollable
  3. Using the left and right arrow keys on your keyboard
  4. With your mouse scroll wheel

Configuration

There are many other ways of using this tool than can be illustrated in the demos provided here. It is important to realize that elements being setup for scrolling can contain any HTML: text, images, forms, Flash objects, or any combination of the above.

The tool is always initialized by means of a JavaScript call similar to the following:

// select one or more elements to be scrollable-enabled
$("JQUERY SELECTOR").scrollable({

	// one configuration property
	size: 5,

	// ... the rest of the configuration properties
});

Here is a list of all available configuration options:

Property Default value Description
activeClass "active" The CSS class name for a clicked scrollable item. Only valid if you have enabled the clickable property.
api false When this tool is initialized (constructed), the return value is a jQuery object associated with the selector. By setting this property to true, the return value is this tool's JavaScript API instead. If the selector returns multiple elements, the API of the last element will be returned. Read more about accessing the tool API for more information.
clickable true Whether scrolling occurs when an item is clicked inside the scrollable-enabled element. The clicked element is positioned In the center of the scrollable and it is assigned a CSS class name specified in the activeClass configuration property. You can get the index number of the clicked item with the getClickIndex() API call. Note that the getIndex method will not return the index number of the clicked element. It can differ from the seek position.
disabledClass "disabled" The CSS class name for disabled next/nextPage and prev/prevPage elements. For example, the prev element is disabled when there are no previous items to scroll to. Typically you assign visibility: 'hidden' CSS definition for disabled elements.
easing "swing" The type of "easing" applied to the scrolling animation. 'swing' means that there is an acceleration, followed by a constant speed, followed by a deceleration. 'linear' means that the whole animation happens at a constant speed. You can also make your own easing effects.
globalNav false By default the navigational elements needs to have a mutual wrapper element with the scrollable itself. Enable this variable if your navigational elements are not placed under the the same parent element than the scrollable so that they can be found.
hoverClass The CSS class name for the scrollable item which has a mouse pointer over it.
items ".items" The scrollable root element is not directly used as a parent for the scrollable items. The root must have one nested element that contains the actual items. By default scrollable uses the first and only element inside the root to be used as a wrapper for the items. It does not have to have any particular CSS class name. A simple DIV is fine.

If you for some reason have multiple elements inside the root element, then scrollable looks for the element specified by this property. By default an element with the class name "items" is used, but you can use any jQuery selector you like in this property.

See minimal setup for an undertanding of the HTML setup for scrollable.

item If you have different kinds of items under the items element and you only want some of them to work as scrollable items then you can use this parameter to select only those specific items. This is a jQuery selector and typically a tag name such as "div" is enough to select the correct items.
keyboard true Whether or not keyboard arrow key navigation is enabled. The horizontal scroller moves backwards/forwards with the left/right arrow keys; the vertical scroller moves with the up/down keys. The arrow keys are valid for the scrollable that was used most recently. Since version 1.1.0 you can also supply the value 'static' here which means that the scrollable is always controlled with the arrow keys and it does not have to be active.

You can also use the focus() method to specify the focus to a certain scrollable on the page. You can take a look at the A complete scrollable navigational system demo which takes advantage of the "static" value and the focus() method.

If you want to disable the keyboard for a particular scrollable, you can call for example:

// grab second scrollabe and it's API
var instance = $(".horizontal").eq(1).scrollable();

// disable keyboard
instance.getConf().keyboard = false;

// reload is required
instance.reload();
keyboardSteps Defines how many items one keypress advances forward or backward. By default this is the same as the value of the size property.
loop false A property indicating whether scrolling starts from the beginning when the last item is exceeded
next ".next" Selector for the elements to which a "scroll forwards" action should be bound. These elements should have a mutual wrapper element together with the scrollable itself.
nextPage ".nextPage" Selector for the elements to which a "next page" action should be bound. These elements should have a mutual wrapper element together with the scrollable itself.
prev ".prev" Selector for the elements to which a "scroll backwards" action should be bound. These elements should have a mutual wrapper element together with the scrollable itself.
prevPage ".prevPage" Selector for the elements to which a "previous page" action should be bound. These elements should have a mutual wrapper element together with the scrollable itself.
size 5 The number of visible items within the scrollable-enabled HTML element. This property can also be referred to as the "page size", since it defines how many items are moved in a particular direction when either the nextPage or prevPage actions are executed.
speed 400 The time (in milliseconds) of the scrolling animation.
vertical false Whether items will be scrolled vertically. If set to false, items will be scrolled horizontally.
onBeforeSeek This callback function is triggered before items are scrolled. A function which returns false will prevent scrolling from taking place.

The first argument for the callback function is the Event object and the second is the index number the item being seeked to.

You have the ability to change the speed of the animation inside this function by changing the this.getConf().speed configuration option.

onSeek This callback function is triggered after items have been scrolled.

The first argument for the callback function is the Event object and the second is the index number the item being seeked to.

onStart Since 1.1.2. This callback function is triggered just before the items start scrolling. This occurs between the onBeforeSeek and onBeforeSeek events. All API methods rely on the fact that the scollable is already at its target position. By returning false inside this function you can prevent the disabling of the navigational elements. If you want to disable the seeking animation you must return false inside the onBeforeSeek event.

The first argument for the callback function is the Event object and the second is the index number the item being seeked to.

Multiple scrollables and next/prev/nextPage/prevPage actions

If you have multiple scrollables on your page we need to make sure that each navigational element is controlling the right scrollable instance. Let's say we have following call to instantiate multiple scrollables with their own "next" and "prev" elements.

It is possible to instantiate multiple scrollables with the same call. For example, if you have multiple scrollable root elements with the CSS class name "vertical" they can all be instantiated with this:

$(".vertical").scrollable();

Now each of the scrollable uses the default selectors .next and .next to look for the navigational elements causing multiple elements to be returned. How do we know which navigational element controls which scrollable? The problem can be solved by enclosing each scrollable and it's navigational actions inside a mutual wrapper element. For example:

<!-- 1st scrollable and it's navigational actions are wrapped inside an extra DIV -->
<div>
	<a class="next"/>
	<div class="scrollable">
		...
	</div>
	<a class="next"/>
</div>

<!-- 2nd instance -->
<div>
	<a class="next"/>
	<div class="scrollable">
		...
	</div>
	<a class="next"/>
</div>

Using callback functions

Here is an example of an onSeek callback function. Inside any callback function the this variable is a pointer to the scrollable scripting API.

$("div.scrollable").scrollable({
	onSeek: function() {
		alert("current page is " + this.getPageIndex());
	},

	// another configuration variable as an example
	clickable: false

});

See the Using Callback Functions section of the User's Guide for a more detailed description about this important topic.

Scripting API

scrollable has a clean and well-designed API for scripters, with which it is possible to enrich the scrolling user experience. You can get a handle to the API in numerous ways as described in the User's Manual. Here is an example of how to access the API:

// get handle to the API upon initialization
var api = $("div.scrollable").scrollable({api: true});

// perform a simple API call
api.next();

// register a callback function
api.onSeek(function() {

	// here, the 'this' variable points to the API
	this.getPageIndex();

});

// supply a callback function to a regular API call
api.next(function() {

	// again the 'this' variable points to the API
	this.prev();

});

Method index

Method Return value Description
focus() API After this call the keyboard arrow keys will control this particular scrollable instance.
getConf() Object Returns the configuration object for the scrollable instance. Note that this object can be modified and the changes are dynamically reflected in the behaviour of the associated scrollable element.
getClickIndex() number since 1.1.1.. Returns the index number of the item that was clicked the last time. This is only available when the clickable configuration property is set to true.
getIndex() number Returns the current position within the scrollable element. This is the index number of the first visible item of the scrollable. Indexing starts from zero.
getItems() jQuery Returns the scrollable items as a jQuery object.
getItemWrap() jQuery Returns the parent element for the scrollable items as a jQuery object.
getNaviButtons() jQuery Returns navigational buttons (next/prev/prevAll/nextAll) as a single jQuery object. If you are using the navigator plugin it is also appended to this return value.
getPageAmount() number Returns the number of pages which could depend upon the size (as specified in the configuration).
getPageIndex() number Returns the current page index. As an example, if the page size is 5 and the current position (the index) is 7, then the value returned will be 1 (the second page).
getRoot() jQuery Returns the main scrollable element as a jQuery object.
getSize() number Returns the amount of items in the scrollable. Identical to getItems().size().
getVisibleItems() jQuery Returns a list of items that are currently being viewed. Return value is a jQuery object which has as many elements as defined in the size configuration variable.
reload() API scrollable supports the dynamic addition and removal of scrollable elements. Take a look at this demo for more details. After adding or removing items, calling this method ensures that the navigator has the correct number of elements, prev/next buttons function correctly, and click handlers are added for new items.
prev() API Scrolls one item backward.
next() API Scrolls one item forward.
seekTo(index) API Seeks to the specified index.
move(offset) API Moves a certain number of items from the current position. For example, move(2) moves two items forward. Negative numbers move backwards.
prevPage() API Scrolls one page backward.
nextPage() API Scrolls one page forward.
setPage(index) API Seeks to the specific page.
movePage(offset) API Moves a certain number of pages from the current position. For example, move(2) moves two pages forward. Negative numbers move backwards.
begin() API Moves to the beginning. Identical to seek(0).
end() API Moves to the end.
click(index) API Programmatically "clicks" the item at the specified index. Scrolling takes place, the item is made active, and any event handlers are triggered.
onBeforeSeek(fn) API Registers a new callback function that is triggered before items are scrolled. The callback is given as the argument. Returning false in the callback will prevent scrolling from taking place. You can assign multiple onBeforeSeek listeners with this command.
onSeek(fn) API Registers a new callback function that is triggered after items have been scrolled. The callback is given as the argument. You can assign multiple onSeek listeners with this command.
onReload(fn) API Registers a new callback function that is triggered when a reload() call is made. This call is typically called when new items are added inder the items element. Note this call is made once when scrollable is initialized.
bind(names, fn) API Register one or more callbacks to be triggered. See using callbacks for more information.
unbind(names) API Removes callback functions from the tool See using callbacks for more information.

Arguments and return value

All seeking methods (the methods from prev onwards in the above list) accept two additional, optional arguments:

  1. speed this argument is used to specify how long (in milliseconds) the scrolling animation lasts. This overrides the speed property specified in the configuration.
  2. callback this argument is used to specify a function to be called when the scrolling animation finishes. This function is called before the onSeek function and it runs only once (as opposed to onBeforeSeek and onSeek, which are called every time a scolling animation takes place).

Seeking methods always return the current scrollable instance, so you can chain method calls as follows:

// a method chaining example
$("div.scrollable").scrollable().click(0).seekTo(2, 3000, function() {
	this.getConf().easing = 'linear';
	this.end();
});

Although this example probably doesn't represent a real world scenario, it is a good demonstration, and it will work if you try executing it in the Firebug console on the example on this page.

scrollable Graphics

Download tooltip graphics

You can use our graphics as the basis for your design. You can freely change the design as you see fit. Click the image on the right to download a zip file. Before using the graphics, you should consult the User's Guide on how graphics can be used when designing the look and feel of the tools.

Here are a few examples of what is included in the zip file:


Plugins

You can find a demo page that shows all of the plugins in action and their installation notes.

Circular plugin version: 0.5.1

The circular plugin generates an infinite loop for the scrollable items. There is no fixed beginning or end and when you surpass the last item it will magically start from the beginning. The same thing happens if you navigate backwards from the first item. Here is this plugin in action:


This circular feature can be used in horizontal scrollables too. The plugin behaves so that the first and last items are cloned at both ends. When those cloned items are visible the scroll position is changed to the real position of the cloned item. Because of this behavioir there are actually more scrollable items than in the original setup.

Usage details

Here is the JavaScript setup for the example above:

// initialize scrollable together with the circular plugin
$("#infinite").scrollable().circular();

Look at a standalone version of the demo above.

Configuration

Here is a full list of available configuration options:

property default description
api false When the scrollable and its chained plugins are initialized (constructed), the return value is a jQuery object associated with the selector. By setting this property to true, the return value is this tool's JavaScript API instead. If the selector returns multiple elements, the API of the last element will be returned. The api property must be added to the last plugin in the initialization chain. Read more about accessing the tool API for more information.
clonedClass 'cloned' The plugin behaves so that the first and last items are cloned at both ends. These cloned items are assigned the CSS class name given in this configuration variable.

Known issues

This plugin is still in beta stage. It has not been fully tested an in complex setups it may not bahave well. Here are some issues that are not yet solved.

Most of the API methods are overridden so that they return the correct results. As a result of this methodology the following issues exist in the current implementation of this plugin:

method return value description / example
getItems() jQuery Returns both the original and cloned items together.
getSize() integer Returns the amount of the original and cloned items together.
seekTo() integer Does not work properly. Use the move() API call if possible.

If you are using the navigator plugin together with this plugin, you must chain the navigator plugin after this plugin. For example:

// always place the navigator plugin AFTER the circular plugin
$("#myroot").scrollable().circular().navigator();

Autoscroll plugin

Autoscroll plugin provides an automatic scrolling capability. It advances to the next items in pre-configured intervals. Here is a autoscroll plugin in action:



You can configure the number of items being scrolled and the interval of the scrolls. When navigational elements are mouseovered the automatic scrolling is paused.

Usage

Here is the JavaScript setup for the example above:

$("#scroller").scrollable().autoscroll({autoplay: false});

Configuration

Here is a full list of available configuration options:

property default description
api false When the scrolalble and its chained plugins are initialized (constructed), the return value is a jQuery object associated with the selector. By setting this property to true, the return value is this tool's JavaScript API instead. If the selector returns multiple elements, the API of the last element will be returned. The api property must be added to the last plugin in the initialization chain. Read more about accessing the tool API for more information.
steps 1 The number of items being scrolled within a single autoscroll.
interval 1000 The time (in milliseconds) between autoscrolls. If this is the only configuration variable for this plugin you can give the interval value directly for the plugin. For example: $("#scroller").scrollable().autoscroll(2000);
autoplay true When enabled the scrolling starts automatically upon page load. If this is set to false, the autoscroll can be started by using the play() method (see below).
autopause true If this property is set to true then, when any navigational buttons are mouseovered, the autoscrolling will pause.

JavaScript API

The following methods are added to the main JavaScript API of the scrollable and they are ready to be used after the plugin has been installed.

method return value description / example
play API Begins a playable autoscroll.
pause API Pauses the autoscroll and it will resume when mouse has moved away from the navigational buttons.
stop API Stops the autoscroll. Autoscroll can only be resumed by calling the play() method.

Navigator plugin

Navigator plugin will allow your users to more easily navigate between different pages in the scrollable. This plugin is convenient if you have lots of items in a scrollable list. Here is the navigator plugin in action:


HTML setup

Here is the HTML setup for the example above.

<!-- wrapper for navigator elements -->
<div class="navi"></div>

This navigator element will be auto-populated with the type of HTML elements specified by your configuration's naviItem property, as follows:

<div class="navi">
	<a href="0" class="active"></a>
	<a href="1" ></a>
	<a href="2" ></a>
	<a href="3" ></a>
</div>

The number of nested naviItem elements depends on the number of scrollable items you have. It's up to you how you visualize those elements using CSS. The navigator knows which page you are currently viewing, and will assign the class name specified in the activeClass configuration property to the active navigation element.

JavaScript setup

Here is the JavaScript setup for the example above.

// initialize scrollable together with the navigator plugin
$("#browsable").scrollable().navigator();

Manual setup

You can also use an existing HTML structure as a navigator. Here is an example:

<!-- manual navigator configuration -->
<ul class="tabs">
	<li><a href="#first">First item</a></li>
	<li><a href="#second">Second item</a></li>
	<li><a href="#third">Third item</a></li>
</ul>

This can be setup as a navigator by doing the following:

$("jquery selector").scrollable().navigator({

	// ul.tabs now functions as our navigator
	navi:'ul.tabs'
});

The items inside navigator can be anything such as LI, A, SPAN or P elements. By default the plugin uses the direct children as navigator items but you can supply naviItem configuration that will select the specified child elements to be used as navigator items.

If you are using A tags inside the wrap and you supply href attributes for them you have the added benefit of automatically the seeking to the correct item when you enter the page with a matching "hash" on the URL. For example if you go to an URL mypage.html#second for the above setup the scrollable will automatically seek to the Second item. You can see an example of this here. Note that the third tab is automatically opened.

Configuration

Here is a full list of available configuration options:

property default description
api false When the scrollable and its chained plugins are initialized (constructed), the return value is a jQuery object associated with the selector. By setting this property to true, the return value is this tool's JavaScript API instead. If the selector returns multiple elements, the API of the last element will be returned. The api property must be added to the last plugin in the initialization chain. Read more about accessing the tool API for more information.
navi ".navi" Selector for the element that contains a navigator for switching between pages. You can have any amount of navigator elements on your page and they will all do the same thing. If you want to instantiate multiple scrollables with a navigator instance then you should read this.
activeClass "active" The CSS class name for the navigator item which corresponds to the current page.
naviItem

The HTML element name for navigational items which are auto-populated inside the navigator. If none is supplied the A tag will be used.

In manual setup this property is used to select the elements inside the root element that will be used as navigator items. The activeClass CSS class name is assigned for these items. If this property is not supplied the direct children for the root element are used as navigator items.

idPrefix since 1.1.2. By supplying a value here the navigator generates an ID attribute for each item so that they can be uniquely styled with CSS. For example, the value "foo" generates the IDs: "foo0", "foo1", "foo2" and so on.
indexed false If this is enabled then the auto-populated navigator elements will have an index number.

JavaScript API

The navigator plugin overrides the getNaviButtons methods of the scrollable API so that it will also contain the navigator element.

Mousewheel plugin

Mousewheel plugin enables scrolling with your mousewheel. Use the mousewheel on top of the scrollable below to see it in action:


Usage

Here is the JavaScript setup:

// initialize scrollable together with the mousewheel plugin
$("#wheeled").scrollable().mousewheel();

Configuration

Here is a full list of available configuration options:

property default description
api false When the scrollable and its chained plugins are initialized (constructed), the return value is a jQuery object associated with the selector. By setting this property to true, the return value is this tool's JavaScript API instead. If the selector returns multiple elements, the API of the last element will be returned. The api property must be added to the last plugin in the initialization chain. Read more about accessing the tool API for more information.
speed 50 The scrolling speed on each mousewheel "step". If this is the only configuration variable for this plugin you can give the speed value directly for the mousewheel plugin. For example: $("#scroller").scrollable().mousewheel(100);

The wheel plugin

This plugin is based on Three Dub Media's wheel plugin which is a smaller, simplified interpretation of the Brandon Aaron's well-known special event, "Mouse Wheel Extension". Thank you! If you have downloaded the mousewheel plugin this wheel plugin is also ready to be used as a standalone tool. Here is how you can use it:

// make #myelement listen to mousewheel events
$("#myelement").wheel(function(event, delta) {

});

Whenever the mousewheel is used with the selector element, the supplied function is called. It is fed with two arguments. The first one is the jQuery event object and the second one specifies how much the wheel was rotated. A positive value for delta means movement downwards and a negative value means movement upwards.