Scroll to first item of jcarousel

Chris picture Chris · Jan 4, 2011 · Viewed 12.5k times · Source

I have multiple instances of jcarousel on a page within a tabbed interface. I need to be able to scroll to the first item of each carousel when the relevant tab is clicked and am unsure how to do this. I've looked at the static controls example (http://sorgalla.com/projects/jcarousel/examples/static_controls.html) but cannot fathom how to get this working for multiple carousels.

Any help would be greatly appreciated. My work-in-progress is here: http://www.brainsdesign.com/client/Lab/14512/style.html

Many thanks,

Chris

Answer

Larry Hipp picture Larry Hipp · Jan 4, 2011

You can use something like:

jQuery('#myCarousel')
     .jcarousel('scroll',position); 

Where position is the start of your jcarousel or the index you want to get to.

This is from the jquery.jcarousel.js source file:

 /**
     * Scrolls the carousel to a certain position.
     *
     * @method scroll
     * @return undefined
     * @param i {Number} The index of the element to scoll to.
     * @param a {Boolean} Flag indicating whether to perform animation.
     */
    scroll: function(i, a) {
        if (this.locked || this.animating) {
            return;
        }

        this.pauseAuto();
        this.animate(this.pos(i), a);
    },