Created
May 10, 2011 13:42
-
-
Save c4urself/964491 to your computer and use it in GitHub Desktop.
Simple jQuery Click Carousel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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