Skip to content

Instantly share code, notes, and snippets.

@c4urself
Created May 10, 2011 13:42
Show Gist options
  • Save c4urself/964491 to your computer and use it in GitHub Desktop.
Save c4urself/964491 to your computer and use it in GitHub Desktop.
Simple jQuery Click Carousel
// szs Shizzle JS Selector
ccarousel.init = function(szsItems, szsButtonPrev, szsButtonNext) {
var numVisible = 4;
var aAllItems = $(szsItems);
renewList = function() {
aAllItems = $(szsItems);
};
aItems = $(szsItems);
oLeft = $(szsButtonPrev);
oRight = $(szsButtonNext);
oParent = $(aItems[0]).parent();
$(aItems).clone().prependTo(oParent);
$(aItems).clone().appendTo(oParent);
oLeft.click(function() {
renewList();
last = aAllItems.eq(-1).detach();
last.prependTo(oParent);
renewVisible();
});
oRight.click(function() {
renewList();
first = aAllItems.eq(0).detach();
first.appendTo(oParent);
renewVisible();
});
getVisible = function() {
renewList();
return aAllItems.slice(aItems.length, aItems.length + numVisible);
};
renewVisible = function() {
aVisibleItems = getVisible();
aAllItems.hide();
aVisibleItems.show();
}
renewVisible();
};
$(document).ready(function() {
ccarousel.init('ul.ccarousel-list > li', 'div.ccarousel-prev', 'div.ccarousel-next');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment