Search code examples
fancybox

Fancybox3 multiple links to same gallery without duplication


I have a gallery of images and a bunch of links to it. However images are duplicated.

Code example:

<a data-fancybox="group" href="foto-1.jpg" ><img src="thumb1.jpg" /></a>
<a data-fancybox="group" href="foto-2.jpg" ></a>
<a data-fancybox="group" href="foto-3.jpg" ></a>

<a data-fancybox="group" href="foto-1.jpg" >Show More Images</a>

This cause image duplication in gallery.

How can I make a multiple links to the same object without duplications in Fancybox3?


Solution

  • You could, for example, replace

    <a data-fancybox="group" href="foto-1.jpg" >Show More Images</a>

    with something like this:

    <a id="more" href="foto-1.jpg" >Show More Images</a>
    
    <script>
        $("#more").on('click', function() {
            $('[data-fancybox="group"]').eq(0).trigger('click');
    
            return false;
        });
    </script>