0

I am using jCarousel as below:

jcarousel_add('#jcarousel',
  array('vertical' => false, 'scroll' => 3, 'horizontalDirection' => $direction, 'initCallback' => 'slCarousel_initCallback')
);

How can I manually slide the carousel?

When I run jQuery("#jcarousel").jcarousel().next();, in Firebug I get the following:

>>> jQuery("#jcarousel").jcarousel().next();
[]

I have tried this as well in the Firebug console:

var carousel = jQuery("#jcarousel").data('jcarousel');
//alert (carousel);
carousel.next();

I got the following:

>>> var carousel = jQuery("#jcarousel").data('jcarousel'); carousel.next()
TypeError: carousel is undefined
  • Are you using jcarousel_add() correctly? According to module README.txt, the first parameter is a class name, not ID. – rocketeerbkw Aug 15 '11 at 15:59
  • it is okay for both... you can use jcarousel_add('#id') or jcarousel_add('.class') ,,, however, i tried both of them and got the same !! :( – Alaa Aug 15 '11 at 19:43
2

I fixed it by creating a global variable, and then assigning the value of the carousel to it.

var global_jc="";
function slCarousel_initCallback(carousel) {
  global_jc=carousel;
  // ...
}

Wherever I want to use next(), I use the following code:

global_jc.next();
1

According to jCarousel Docs you need to use

var carousel = jQuery("#jcarousel").data('jcarousel');

You can then use controls (as demonstrated at this example)

carousel.next()
  • I have tried this already in firebug and it gives >>> var carousel = jQuery("#jcarousel").data('jcarousel'); carousel.next() TypeError: carousel is undefined and by alerting carousrl i got "undefined" – Alaa Aug 15 '11 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.