Search code examples
jqueryfancybox

How to create separate Fancybox galleries on the same page?


We are using jQuery 1.7.1 and Fancybox 1.3.4. I am brand new to Fancybox. I have never used it before yesterday, but it is used widely on a site that I am working on. The person who set up Fancybox was terminated because he was ... irrelevant. :)

I am creating a product comparison page. Up to four products will display on a single page. Each product may have up to five images specific to that product.

Currently, when I click on any image, Fancybox pops open and creates a gallery of all of the images on the page. So, if I have one product with five images, there is a five image gallery. If I have four products with five images, there is one gallery with twenty images. This doesn't work well for me.

What I want is for each product to have its own gallery. If a they click on Product A, they will see only the images associated with Product A. If they click on Product B... you get it.

How can I make Fancybox create separate galleries on a single page?

EDIT

Currently, my rel attribute is set to 'autoGallery'. One of the answers below suggested that I change it to something like this, which would produce what I am looking for:

<img rel='Gallery1'>
<img rel='Gallery1'>
<img rel='Gallery2'>
<img rel='Gallery2'>
<img rel='Gallery3'>
<img rel='Gallery3'>

If I change the rel attribute to anything except for 'autoGallery', clicking on the image just opens the image into a new window.


Solution

  • Just assign a different rel attribute to each gallery

    <a class="fancybox" rel="gallery01" href="product01/image01.jpg">one</a>
    <a class="fancybox" rel="gallery01" href="product01/image02.jpg">one</a>
    <a class="fancybox" rel="gallery01" href="product01/image03.jpg">one</a>
    <a class="fancybox" rel="gallery01" href="product01/image04.jpg">one</a>
    
    <a class="fancybox" rel="gallery02" href="product02/image01.jpg">two</a>
    <a class="fancybox" rel="gallery02" href="product02/image02.jpg">two</a>
    <a class="fancybox" rel="gallery02" href="product02/image03.jpg">two</a>
    
    <a class="fancybox" rel="gallery03" href="product03/image01.jpg">three</a>
    <a class="fancybox" rel="gallery03" href="product03/image02.jpg">three</a>
    <a class="fancybox" rel="gallery03" href="product03/image03.jpg">three</a>
    

    ... and they all can use the same script:

    $(".fancybox").fancybox();