开发者

how to slide jcarousel manually

i am using jcarousel in drupal as below:

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

    );

now to ask the question as simple as possible: how can i slide the carousel manually?? something like

jQuery("#jcarousel").jcarousel().next();

by the way,,, when i run this script jQuery("#jcarousel").jcarousel().next(); in firebug i got this in the console of firebug

>>> jQuery("#jcarousel").jcarou开发者_如何学JAVAsel().next();
[]

I have tried this as well in firebug console

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

and got

>>> var carousel = jQuery("#jcarousel").data('jcarousel'); carousel.next()
TypeError: carousel is undefined

and the result of alert(carousel) was the word undefined


Are you sure the carousel's id is jcarousel? The plugin's documentation suggests jcarousel_add() takes a class name as the first parameter. If that's the case you can access it with $( '.jcarousel' ) if you change it to jcarousel_add( "jcarousel", ... ). Inspect the carousel element or check the page source to see the id and classes.


Did you try:

jQuery('#jcarousel').jcarousel("next");

EDIT: Calling $(foo).jcarousel() with no arguments returns a jQuery object, so calling next() on that will return the next sibling of the carousel. This function: http://api.jquery.com/next/


ok... i fixed it by creating global variable and then assigning the value of the carousel to it

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

and then wherever i want to use next manually i use this

global_jc.next();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜