Return to Snippet

Revision: 49530
at July 24, 2011 05:02 by FatFolderDesigner

Initial Code
/* HTML */
<div class="rotator_container">
    <div id="rotator_prev"></div>
    <div id="rotator_box">
        <div id="rotator_set_1">
            <a href=""><img src="img/bugatti.jpg" /></a>
            <a href=""><img src="img/nissian.jpg" /></a>
            <a href=""><img src="img/porsche.jpg" /></a>
            <a href=""><img src="img/toyota.jpg" /></a>
        <div id="rotator_set_2">
            <a href=""><img src="img/donkeykong.jpg" /></a>
            <a href=""><img src="img/hero.jpg" /></a>
            <a href=""><img src="img/spyvsspy.jpg" /></a>
            <a href=""><img src="img/superzaxxon.jpg" /></a>
        <div id="rotator_set_3">
            <a href=""><img src="img/b1.jpg" /></a>
            <a href=""><img src="img/b2.jpg" /></a>
            <a href=""><img src="img/b3.jpg" /></a>
    <div id="rotator_next"></div>

/* CSS */
    width: 354px;
    height: 254px;
    background-color: black;
    display: inline-block;
    vertical-align: middle;
    padding: 4px;
    overflow: hidden;

/* jQuery */
    var lastloaded = 1
    var maxloadable = $('#rotator_box > div').length;
    function update(){
        $("#rotator_box > *:visible").fadeOut(175,function(){

Initial URL

Initial Description
The code is in three parts, a HTML layout (with some requirements I'll go over below), some CSS code (again, requirements below) and the actual jQuery code. I go over all the code in detail at the link, but I'll give a quick rundown od the jQuery as well.

The button that control next and previous are given IDs of "rotator_next" and "rotator_prev" respectively. The content shows in the a div with the ID "rotator_box". Inside the "rotator_box" div there a other divs with the IDs "rotator_set_#" where # is a number, 1 through as many pages as you want.

The CSS:
The important part of the style is the width, height, and overflow property. The width and height allow you to control the way the items are display, be it column, grid, or standard horizontal orientation.

The jQuery:
The script runs on document load and sets up a click even for the next and previous buttons. This evens add or subtract the lastviwed accordingly and run the update function, which does the fading out and fading in. After the contents have faded in it sets the opacity to 1, this is just to prevent any overzealous user from clicking so fast it makes a page stop wanting to fade fully in.

Like I said, theres more info and an example at the link.

Initial Title
Simple jQuery Rotator

Initial Tags
script, jquery

Initial Language