Skip to content

Instantly share code, notes, and snippets.

@komplexb
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komplexb/3de8e8d46f34ea13970f to your computer and use it in GitHub Desktop.
Save komplexb/3de8e8d46f34ea13970f to your computer and use it in GitHub Desktop.
dynamic list navigation: used to toggle forward/backward; next/back on lists, galleries and similar constructs
function moveCarouselItems (isDirectionForward) {
var currentImage = parentObject.find('.current_image'),
carouselItems = parentObject.find('ul li'),
position = carouselItems.index(currentImage);
if (isDirectionForward === null || isDirectionForward === undefined )
isDirectionForward = true;
if(isDirectionForward) {
if(position < carouselItems.length - 1) {
// do actions associated with going forward
$('.current_image').removeClass('current_image').next().addClass('current_image'); //go to next image
}
else {
// loop around if you want to
carouselItems.removeClass('current_image').first().addClass('current_image'); // if at the end go to first image
}
}
else {
if(position === 0) {
// do actions associated with going back wards
carouselItems.removeClass('current_image').last().addClass('current_image'); // if at the beginnning go to last image
}
else {
$('.current_image').removeClass('current_image').prev().addClass('current_image'); // go to previous image
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment