Fancybox multiple links to same gallery without duplication
Asked Answered
M

1

7

So I have a gallery of images, and a few links to it. Something like that

<a href="/images/1.jpg" rel="1">title</a>
<a href="/images/1.jpg" rel="1">link to first image</a>
<a href="/images/2.jpg" rel="1">link to second image</a>
<a href="/images/3.jpg" rel="1">link to third image</a>

This is cause first image to duplicate in fancybox. Like this: http://filebeam.com/2dec41a1820f2525f040424578c4421c.jpg

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

Mutt answered 13/11, 2012 at 10:30 Comment(0)
B
15

If all links are visible and clickable, then you could create a custom click handler for the first one that opens fancyBox gallery from the rest -

<a data-trigger-rel="gallery" class="fancybox-trigger" href="http://fancyapps.com/fancybox/demo/1_b.jpg"><img src="http://fancyapps.com/fancybox/demo/1_s.jpg" alt=""/></a>

<br />
<br />

<a rel="gallery" class="fancybox" href="http://fancyapps.com/fancybox/demo/1_b.jpg"><img src="http://fancyapps.com/fancybox/demo/1_s.jpg" alt=""/></a>

<a rel="gallery" class="fancybox" href="http://fancyapps.com/fancybox/demo/2_b.jpg"><img src="http://fancyapps.com/fancybox/demo/2_s.jpg" alt=""/></a>

$(".fancybox-trigger").click(function() {

    $("a[rel='" + $(this).data('trigger-rel') + "']").eq(0).trigger('click');

    return false;

});


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

See in action - http://jsfiddle.net/g9R4H/

Baribaric answered 13/11, 2012 at 10:41 Comment(1)
FYI, fancybox v3 has trigger element feature, simply use data-fancybox-trigger attribute with the value of fancybox group name - codepen.io/fancyapps/pen/VGoRqO?editors=1010Baribaric

© 2022 - 2024 — McMap. All rights reserved.