Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 67 additions & 12 deletions simple.carousel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/**
* Bartosz Szczecinski baphemot@gmail.com
*
* Fork of:
*
* Simple Carousel
* Copyright (c) 2010 Tobias Zeising, http://www.aditu.de
* Licensed under the MIT license
Expand All @@ -20,8 +24,12 @@ $.fn.simplecarousel = function( params ) {
current: 0,
items: 0,
slidespeed: 600,
visible: 1,
pagination: false
visible: 4,
// nuber of frames that prev/next should skip
jump: 4,
pagination: false,
// enable / disable looping on ends
noloop: true
};
var config = $.extend(defaults, params);

Expand Down Expand Up @@ -58,22 +66,67 @@ $.fn.simplecarousel = function( params ) {
$(item).css('float','left');
});

if(config.noloop == true) {
if(config.current == 0) {
jQuery(config.prev).addClass('disabled');
}
else {
jQuery(config.prev).removeClass('disabled');
}

if(config.current+config.visible == config.items) {
jQuery(config.next).addClass('disabled');
}
else {
jQuery(config.next).removeClass('disabled');
}
}

// function for sliding the carousel
var slide = function(dir, click) {
if(typeof click == "undefined" & config.auto==false)
return;



if(dir=="next") {
config.current += config.visible;
if(config.current>=config.items)
config.current = 0;
config.current += config.jump;
if(config.noloop == true) {
if(config.current + ((config.visible >= config.jump) ? config.visible - config.jump : config.jump) >= config.items) {
config.current -= config.jump;
}
}
else {
if(config.current>=config.items)
config.current = 0;
}


} else if(dir=="prev") {
config.current -= config.visible;
if(config.current<0)
config.current = (config.visible==1) ? config.items-1 : config.items-config.visible+(config.visible-(config.items%config.visible));
config.current -= config.jump;
if(config.current<0) {
if(config.noloop == true) config.current += config.jump;
else config.current = (config.visible==1) ? config.items-1 : config.items-config.visible+(config.visible-(config.items%config.visible));
}

} else {
config.current = dir;
}

if(config.noloop == true) {
if(config.current == 0) {
jQuery(config.prev).addClass('disabled');
}
else {
jQuery(config.prev).removeClass('disabled');
}

if(config.current+config.visible >= config.items) {
jQuery(config.next).addClass('disabled');
}
else {
jQuery(config.next).removeClass('disabled');
}
}

// set pagination
if(config.pagination != false) {
Expand Down Expand Up @@ -125,13 +178,15 @@ $.fn.simplecarousel = function( params ) {

// set event handler for next and prev
if(config.next!=false)
config.next.click(function() {
config.next.click(function(e) {
e.preventDefault();
slide('next',true);
});


if(config.prev!=false)
config.prev.click(function() {
config.prev.click(function(e) {
e.preventDefault();
slide('prev',true);
});

Expand All @@ -141,4 +196,4 @@ $.fn.simplecarousel = function( params ) {
slide('next');
}, config.auto);
}
})(jQuery);
})(jQuery);