Fancybox multiple links to same gallery without duplication

∥☆過路亽.° 提交于 2019-11-28 03:41:56

问题


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?


回答1:


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/



来源:https://stackoverflow.com/questions/13359115/fancybox-multiple-links-to-same-gallery-without-duplication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!