8/31/2010

HoverScroll jQuery Plugin

To be able to use the HoverScroll plugin you must first include the script and css in the head section of your page along with the jquery library.

>
<head>

link type="text/css" rel="stylesheet" href="jquery.hoverscroll-0.1.0.css" />

script type="text/javascript" src="jquery.js">script>
script type="text/javascript" src="jquery.hoverscroll-0.1.0.js">script>

head>


Then, you will need some html markup:

1.<ul id="my-list">
2. <li style="width:67px; height:50px;"><img src="images/maja1_th.jpg" />li>
3. <li style="width:67px; height:50px;"><img src="images/maja2_th.JPG" />li>
4. <li style="width:67px; height:50px;"><img src="images/maja3_th.JPG" />li>
5. <li style="width:67px; height:50px;"><img src="images/maja4_th.JPG" />li>
6.ul>

Note for horizontal HoverScrolls:
The width and height is specified on each list item because if the images are not loaded as fast as the code (which happens often) the script cannot reliably determine the width of the content.
When this happens only one item is shown from the list. Generating HoverScrolls upon the window.onload event within a 10ms setTimeout call and specifying the width and height of each item (in the html or in a separate css file) can resolve this problem. The sample above was generated by a php script which determines each images width and height and prints it out in the html, but it is abit useless in this example as all the images have the same size.


Finally, in the head again (after including the scripts) add the following block of code to generate the HoverScroll and you're all good to go!
This creates a horizontal hover scroll list (see further down for default parameters control).

1.<script type="text/javascript">
2.$(document).ready(function() {
3. $('#my-list').hoverscroll();
4.});
5.script>


View the complete source of this example

Plugin reference

$('selector').hoverscroll ( [ params {Object} ] );

params {Object}
List of parameters that define the shape and behaviour of the list

01.{
02. vertical: false, // Display the list vertically or horizontally
03.
04. width: 400, // Width of the list container
05. height: 50, // Height of the list container
06.
07. arrows: true // Display direction indicator arrows or not
08. arrowsOpacity: 0.7 // Max possible opacity of the arrows
09.
10. debug: false // Debug output in the firebug console
11.}

$.fn.hoverscroll.params

These are the HoverScroll default parameters. It can be very useful to override these so you don't have to specify parameters for each HoverScroll call.

For example:

01.// Override default parameters onload
02.$.fn.hoverscroll.params = $.extend($.fn.hoverscroll.params, {
03. vertical : true,
04. width: 67,
05. height: 300,
06. arrows: false
07.});
08.
09.// Generate hoverscroll with overridden default parameters
10.$('#my-list').hoverscroll();

Generated markup

Here is a sample of markup generated by hoverscroll (note: you must not use this markup in your code else HoverScroll will not work properly) :

01.<div class="ui-widget-content hoverscroll horizontal">
02. <div class="listcontainer">
03. <ul id="my-list" class="list ui-helper-clearfix">
04. <li class="item"><img src="images/maja1_th.jpg" />li>
05. <li class="item"><img src="images/maja2_th.JPG" />li>
06. <li class="item"><img src="images/maja3_th.JPG" />li>
07. <li class="item"><img src="images/maja4_th.JPG" />li>
08. <li class="item"><img src="images/maja5_th.JPG" />li>
09. <li class="item"><img src="images/maja6_th.JPG" />li>
10. <li class="item"><img src="images/maja7_th.JPG" />li>
11. <li class="item"><img src="images/maja8_th.JPG" />li>
12. <li class="item"><img src="images/maja9_th.JPG" />li>
13. <li class="item"><img src="images/maja10_th.JPG" />li>
14. ul>
15. <div class="arrow left">div>
16. <div class="arrow right">div>
17. div>
18.div>

As you can see, HoverScroll integrates with the jQuery UI by implementing one of its CSS classes.


Download the HoverScroll jQuery plugin

No comments: