This project is read-only.

jQuery Image Rotator Quick Start


  • This plugin was developed on top of jQuery 1.4.4.
  • jQuery.imageRotator expects to be called on an element which contains
    • an <img> tag of class "imageRotator"
    • optionally, a surrounding <a> tag of class "imageRotator"

Documentation Assumptions

Samples in this document assume that the container element has an id of 'imageRotatorContainer'. This is not a required convention.

Using the plugin

Given the expected HTML as described above, you can simply call the plugin on the container:

There are two options.
  • rotationTimerMs - the time in milliseconds between rotations
  • images - a JSON array of objects with the following properties
    • src - the src attribute for the image
    • alt - the alt text for the image
    • href - only used if the surrounding <a> tag is present, this is the href to be applied

So, the following rotates between two images at a speed of 2000 ms. (2 sec.)
'images':[src":"","alt":"A pair of dogs","href":",src":"","alt":"LOL Top Hat!","href":"],

Handling varying image sizes

First, set the size of the container. In the case below, we are using a table, but it could just as easily be a div.
Next, set the max- sizes of the img to match.
Finally, use expressions to constrain the actual size of the img. Note that in this example, the img will not stretch to fill the container. It will only shrink to fit.

We are setting styles inline for the sake of the documentation. You could, and probably should, do much of this in your CSS.
<table style='width:200px;height:200px;padding:0;'>
<td id='imageRotator' style='padding:0;margin:0;border:1px solid black;'>
<a href='#' class='imageRotator'>
<!-- By setting the max width/height and using expressions for width/height we constrain the image's size regardless of the rotated items-->
<img style='max-width:200px;max-height:200px;width:expression(this.width > 200px ? 200px : true);height:expression(this.height > 200px ? 200px : true)'
class='imageRotator' src='' alt='A pair of dogs' />

Integration with prettyPhoto

By adding rel='prettyPhoto' to your <a> tag and calling $('a.imageRotatorContainer').prettyPhoto();

To fully document prettyPhoto is beyond the scope of this project. For more information, please refer to their website.

Last edited Jan 19, 2011 at 4:53 AM by druttka, version 3


No comments yet.