After initialization, you can call the following methods on the jCarousel instance:
See Calling methods on the jCarousel instance for how to call methods.
scroll(target [, animate [, callback]])Scrolls to a specific item or relative by a given offset.
-
The target item to which the carousel should scroll.
-
Scrolls to the item at the given index (Note that indexes are 0-based).
Example:
$('.jcarousel').jcarousel('scroll', 0);
-
Scrolls to the item at the given index counting backwards from the end of the list.
Example:
$('.jcarousel').jcarousel('scroll', -1);
-
Scrolls to the given object.
Example:
$('.jcarousel').jcarousel('scroll', $('.jcarousel li:eq(2)'));
-
Scrolls the carousel forward by the given offset relatively from the current position.
Example:
$('.jcarousel').jcarousel('scroll', '+=1');
-
Scrolls the carousel backwards by the given offset relatively from the current position.
Example:
$('.jcarousel').jcarousel('scroll', '-=1');
-
-
If the argument
animateis given andfalse, it just jumps to the position without animation. -
If the argument
callbackis given and a valid function, it is called after the animation is finished.The function receives a boolean as first argument indicating if a scrolling actually happend.
It can be false for the following reasons:
- The carousel is already animating
- The target argument is invalid
- The carousel is already on the requested position
- An event has cancelled the scrolling
$('.jcarousel').jcarousel('scroll', '+=1', true, function(scrolled) {
if (scrolled) {
console.log('The carousel has been scrolled');
} else {
console.log('The carousel has not been scrolled');
}
});reload([options])Reloads the carousel. This method is useful to reinitialize the carousel if you have changed the content of the list from the outside or want to change options that affect appearance of the carousel at runtime.
-
A set of configuration options.
$('.jcarousel').jcarousel('reload', {
animation: 'slow'
});destroy()Removes the jCarousel functionality completely. This will return the element back to its initial state.
$('.jcarousel').jcarousel('destroy');list()Returns the list element as jQuery object.
var list = $('.jcarousel').jcarousel('list');Note: The item-related methods return different results depending on the state of the carousel. That means for example, that after each scroll, these methods return a different set of items.
The following example illustrates how to use these methods inside event callbacks:
$('.jcarousel')
.on('jcarousel:animateend', function(event, carousel) {
var currentFirstItem = $(this).jcarousel('first');
var currentLastItem = $(this).jcarousel('last');
});list()Returns all items as jQuery object.
var items = $('.jcarousel').jcarousel('items');target()Returns the targeted item as jQuery object.
var target = $('.jcarousel').jcarousel('target');first()Returns the first visible item as jQuery object.
var first = $('.jcarousel').jcarousel('first');last()Returns the last visible item as jQuery object.
var last = $('.jcarousel').jcarousel('last');visible()Returns all visible items as jQuery object.
var visible = $('.jcarousel').jcarousel('visible');fullyvisible()Returns all fully visible items as jQuery object.
var fullyvisible = $('.jcarousel').jcarousel('fullyvisible');