Skip to content

Instantly share code, notes, and snippets.

@chrisdhanaraj
Last active August 29, 2015 14:08
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 chrisdhanaraj/b483a691e997165a797b to your computer and use it in GitHub Desktop.
Save chrisdhanaraj/b483a691e997165a797b to your computer and use it in GitHub Desktop.
Advanced Carousel
function carousels(element, jump) {
var carousel;
carousel = $(element).cycle({
fx: 'carousel',
timeout: 0,
allowWrap: false
});
var totalSlides = $(element).data('cycle.opts').slideCount;
$(element).find('.next').on('click', function() {
nextSlide();
});
$(element).find('.prev').on('click', function() {
prevSlide();
});
function nextSlide() {
var currentSlide = $(element).data("cycle.opts").currSlide;
if (currentSlide + (jump * 2) > totalSlides) {
$(element).cycle('goto', totalSlides - jump);
} else {
$(element).cycle('goto', currentSlide + jump);
}
}
function prevSlide() {
var currentSlide = $(element).data("cycle.opts").currSlide;
if (currentSlide - jump < 0) {
$(element).cycle('goto', 0);
} else {
$(element).cycle('goto', currentSlide - jump);
}
}
}
function getCarousels(classname, jump){
var carouselArray = $(classname);
for (var i = 0; i < carouselArray.length; i++) {
var carouselItem = carousels(carouselArray[i], jump);
}
}
getCarousels('.carousel', 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment