Dynamic Load Ajax of 2 jcarousel same page

View: New views
2 Messages — Rating Filter:   Alert me  

Dynamic Load Ajax of 2 jcarousel same page

by Joshp :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have searched and haven't quite come up with an answer.  I'm trying to load 2 separate carousels on the same page from different .txt file sources.  I'm not sure what I need to change.  I tried putting two separate Javascript jcarousel code on the same page and just changed the jQuery.get("../slideshow.txt", function(data) and additionally changed the jQuery("#mycarousel2").jcarousel.  However only one source shows up in both carousels.

Any help would be greatly appreciated.

Re: Dynamic Load Ajax of 2 jcarousel same page

by jso :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Joshp wrote:
I have searched and haven't quite come up with an answer.  I'm trying to load 2 separate carousels on the same page from different .txt file sources.  I'm not sure what I need to change.  I tried putting two separate Javascript jcarousel code on the same page and just changed the jQuery.get("../slideshow.txt", function(data) and additionally changed the jQuery("#mycarousel2").jcarousel.  However only one source shows up in both carousels.

Any help would be greatly appreciated.
you need a callback function for each carousel since they load different files. You can try that (untested):

function mycarousel_itemLoadCallback(url, carousel, state)
{
    // Since we get all URLs in one file, we simply add all items
    // at once and set the size accordingly.
    if (state != 'init')
        return;

    jQuery.get(url, function(data) {
        mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data);
    });
};

And then pass the following anonymous function as parameter:

jQuery('#mycarousel').jcarousel({
    itemLoadCallback: function (carousel, state) { mycarousel_itemLoadCallback('../slideshow1.txt', carousel, state); }
});

and for the second carousel:

jQuery('#mycarousel').jcarousel({
    itemLoadCallback: function (carousel, state) { mycarousel_itemLoadCallback('../slideshow2.txt', carousel, state); }
});

Jan
LightInTheBox - Buy quality products at wholesale price