How to prevent showing same image when there are two anchors opening the same gallery with fancy box on same page?

有些话、适合烂在心里 提交于 2019-12-11 04:49:05

问题


I have a page that has two ways to open a gallery of images/videos that open in fancybox 2.

The problem is that because there are two links that open the start of the gallery with the first image, the first image is displayed twice in the gallery.

Here is my example http://www.londonsitedesign.co.uk/test.html

How can I prevent the first image being displayed twice in the gallery?


回答1:


If the first link will only start the fancybox gallery, then it doesn't need to have the fancybox class (neither an href attribute for instance)

You could actually use a different class for it (e.g. fancyboxLauncher)

<a class="fancyboxLauncher" href="#" rel="falling">Slideshow</a>

... and bind a click event to it like :

$(".fancyboxLauncher").on("click", function(){
    $(".fancybox").eq(0).trigger("click");
    return false;
});

... notice that we used the method .eq(0) to fire the gallery from the first item, otherwise it will start from the last. Also notice that .on() requires jQuery v1.7+

You still need to have this code for the fancybox gallery

$(".fancybox").fancybox({
    // API options here
});

Check JSFIDDLE



来源:https://stackoverflow.com/questions/17338918/how-to-prevent-showing-same-image-when-there-are-two-anchors-opening-the-same-ga

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