Skip to content

Instantly share code, notes, and snippets.

@ataylorme
Created January 21, 2013 16:27
Show Gist options
  • Save ataylorme/4587215 to your computer and use it in GitHub Desktop.
Save ataylorme/4587215 to your computer and use it in GitHub Desktop.
Simple Image rotator
function rotateImages(slides) {
//Hide all slides
slides.hide();
//Show first slide
slides.eq(0).show();
//Set current slide to 0
var current = 0;
//Set total slides
var total = slides.length;
//Subtract one to make up for zero index
total--;
//Next slide function
function next_slide() {
//Fadout current slide
slides.eq(current).fadeOut('500', function () {
//Make current slide next slide. If we are at the end make current slide the first slide.
if (current === total) {
current = 0;
} else {
current++;
}
//Fade in next slide.
slides.eq(current).fadeIn('500');
}); //end fadeOut function
} //end next_slide function
//Set slide speed to 5 seconds
setInterval(next_slide, 5000);
} //end rotateImages function
//pass the rotateImages function the selector of the items to rotate, not their container
rotateImages(jQuery('#sidebar .image-slideshow img.home-thumb'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment