Usage ===== * [Calling methods on the jCarousel instance](#calling-methods-on-the-jcarousel-instance) * [Navigating the carousel](#navigating-the-carousel) * [Defining the number of visible items](#defining-the-number-of-visible-items) * [Vertical carousels](#vertical-carousels) * [RTL (Right-To-Left) carousels](#rtl-right-to-left-carousels) * [Manipulating the carousel](#manipulating-the-carousel) Calling methods on the jCarousel instance ----------------------------------------- If you have created a carousel like: ```javascript $(function() { $('.jcarousel').jcarousel(); }); ``` You can later call methods on the jCarousel instance like: ```javascript $('.jcarousel').jcarousel('scroll', '+=2'); ``` The first argument is the method name. The following arguments are the arguments for the called method. Alternatively, you can first grab the jCarousel instance and call the methods directly on it: ```javascript var instance = $('.jcarousel').data('jcarousel'); instance.scroll('+=2'); ``` See [API](api.md) for all available methods. Navigating the carousel ----------------------- jCarousel offers no built in controls to navigate through the carousel. But you can simply implement navigation controls using the [scroll](api.md#scroll) method. ```javascript $('.jcarousel').jcarousel('scroll', target); ``` A simple example for previous and next controls: ```javascript $('.jcarousel-prev').click(function() { $('.jcarousel').jcarousel('scroll', '-=1'); }); $('.jcarousel-next').click(function() { $('.jcarousel').jcarousel('scroll', '+=1'); }); ``` A more comfortable way is to use a navigation plugin: * [Control Plugin](../plugins/control/) * [Pagination Plugin](../plugins/pagination/) Defining the number of visible items ------------------------------------ You simply define the number of visible items by defining the width (or height for a vertical carousel) of the root element (if you use the default from this document, you do that with the class `.jcarousel` in your stylesheet). This offers a lot of flexibility, because you can define the width in pixel for a fixed carousel or in percent for a flexible carousel. ### Fixed carousel Always 3 visible items: ```css .jcarousel { position: relative; overflow: hidden; width: 300px; } .jcarousel li { float: left; width: 100px; } ``` ### Flexible carousel The number of visible items depend on the width of the root's parent element: ```css .jcarousel { position: relative; overflow: hidden; width: 100%; } .jcarousel li { float: left; width: 100px; } ``` Vertical carousels ------------------ jCarousel tries to auto-detect the orientation by simply checking if the list elements’s height is greater than the list element’s width. If auto-detection doesn't work, you can explicitly pass the `vertical` option: ```javascript $('.jcarousel').jcarousel({ vertical: true }); ``` RTL (Right-To-Left) carousels ----------------------------- jCarousel tries to auto-detect if the carousel should run in RTL mode by looking for a `dir` attribute with the value `rtl` on the root or any of its parent elements. ```html