javascriptjqueryfancybox

How to open fancybox with array of images


I have an array of images URLs in Javascript:

photos= ['img1.jpg','img2.jpg',...]

I'm using Fancybox 2.

How can I open Fancybox with the images of the array?

$('#start_slides').fancybox({
    'openEffect'    :   'elastic',
    'closeEffect'   :   'elastic',
    'openSpeed'     :   600, 
    'closeSpeed'    :   200,
    helpers : {
        buttons : {}
    }
});

$.fancybox.open(photos,{});

But this is only showing a fancybox with the URLs as text.

My final result should be a fancybox with showing the images like a slideshow.


Solution

  • Found a solution: The photos array must be in the format:

    photos = [ {href : 'img1.jpg', title : 'Title'}, {href : 'img2.jpg', title : 'Title'} ]
    

    Then it is working.

    And the initializing is done correctly by:

    $('#start_slides').fancybox();
    
    $.fancybox.open(photos,{
        'openEffect'    :   'elastic',
        'closeEffect'   :   'elastic',
        'nextEffect'    :   'fade',
        'openSpeed'     :   600, 
        'closeSpeed'    :   200,
        helpers : {
            buttons : {}
        }
    });