Skip to content

Instantly share code, notes, and snippets.

@ryanmcgrath
Forked from anonymous/gist:429042
Created June 7, 2010 19:37
Show Gist options
  • Save ryanmcgrath/429075 to your computer and use it in GitHub Desktop.
Save ryanmcgrath/429075 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
$(document).ready(function(){
$('#slide_one').delay(2000).fadeOut(500, function() {
$('#slide_two').fadeIn(500).delay(2000).fadeOut(500, function() {
$('#slide_three').fadeIn(500).delay(2000).fadeOut(500, function() {
$('#slide_one').fadeIn(500);
});
});
});
});
</script>
@ryanmcgrath
Copy link
Author

var pics = [];

/* Use recursion to loop through the pictures */
function loopPics(index) {
    var previousIndex = index - 1;
    if(previousIndex === 0) previousIndex = pics.length -1;

    pics[previousIndex].fadeOut("fast");
    pics[index].fadeIn("slow");

    setTimeout(function() {
        loopPics(index === pics.length -1 ? 0 : index + 1);
    }, 2000);
}

$(document).ready(function() {
    pics.push($("#slide_one"));
    pics.push($("#slide_two"));
    pics.push($("#slide_three"));
    loopPics();
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment