Skip to content

Instantly share code, notes, and snippets.

@greggb
Created April 24, 2012 02:27
Show Gist options
  • Save greggb/2475588 to your computer and use it in GitHub Desktop.
Save greggb/2475588 to your computer and use it in GitHub Desktop.
Create a slideshow of list items
$("body").on("click", "#next, #prev", function(e){
var visibleslide = $("ul").find(".is-visible");
var totalslides = $("ul li").length-1;
$(visibleslide).removeClass("is-visible");
e.preventDefault();
if ( $(this).attr("id")==="next" ) {
if ( $(visibleslide).index()===totalslides ) {
$("li:eq(0)").addClass("is-visible");
}
else {
$(visibleslide).next("li").addClass("is-visible");
}
}
else {
if ( $(visibleslide).index()===0 ) {
$("li:eq("+totalslides+")").addClass("is-visible");
}
else {
$(visibleslide).prev("li").addClass("is-visible");
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment