jquery - "rel"的多个 Fancybox 2 画廊问题

标签 jquery html fancybox gallery fancybox-2

我见过一些解决类似问题的问题,但似乎没有一个修复方法适合我的情况。基本上我在整个网站的一个页面上有多个 fancybox 画廊,当一个人点击网站上的一个幻灯片时,它会从一个画廊继续到下一个。我希望 galleries/fancybox 实例彼此分开。基本上我需要“rel”类别来保持画廊分开而不是相互渗透。非常感谢任何帮助我已经尝试了一些方法,但似乎没有任何效果。

这是我添加社交媒体按钮的唯一附加 Javascript:

$(function(){
    $(".fancybox")
        .attr('rel', 'gallery')
        .fancybox({
            beforeShow: function () {
                if (this.title) {
                    // New line
                    this.title += '<br />';

                    // Add tweet button
                    this.title += '<a href="https://twitter.com/share" class="twitter-share-button" data-count="none" data-url="' + "http://drewalbinson.com/" + '">Tweet</a> ';

                    // Add FaceBook like button
                    this.title += '<iframe src="http://www.facebook.com/plugins/like.php?href=' + this.href + '&amp;layout=button_count&amp;show_faces=true&amp;width=500&amp;action=like&amp;font&amp;colorscheme=light&amp;height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:110px; height:23px;" allowTransparency="true"></iframe>';
                }
            },
            afterShow: function() {
                // Render tweet button
                twttr.widgets.load();
            },
            helpers : {
                title : {
                    type: 'inside'
                }
            }  
        });

    });

这是我的 HTML 的简化版本:

<!-- Gallery 1 -->

<div class="imagebox">
<a href="g1_img1.png" class="fancybox" rel="gallery1" title="1 of 2">

<img src="g1_img1_small.png" />

</a>

<a href="g1_img2.png" class="fancybox" rel="gallery1" title="2 of 2"></a>

</div>

<!-- Gallery 2 -->

<div class="imagebox">

<a href="g2_img1.png" class="fancybox" rel="gallery2" title="1 of 2">

<img src="g2_img1_small.png" />

</a>

<a href="g2_img2.png" class="fancybox" rel="gallery2" title="2 of 2"></a>

</div>

谢谢!

最佳答案

这部分代码:

$(".fancybox")
    .attr('rel', 'gallery')
    .fancybox({
    .... etc

...正在覆盖您的 html 中的 rel 属性。只需从中删除 .attr() 方法即可:

$(".fancybox")
    .fancybox({
    .... etc

...你会没事的。

关于jquery - "rel"的多个 Fancybox 2 画廊问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17032398/

相关文章:

javascript - Snap.svg 拖动多个组

javascript - CKFinder TypeError : t. event.special.swipe 未定义

html - 我在哪里可以找到包含网络安全字体的列表?

html - 无法对齐标签,在表单中输入

javascript - 使用按钮关闭 fancybox 模式

javascript - Fancybox 出现问题 (P

javascript - .slideToggle() 在使用 Jquery 3.1.1 时不起作用

jquery - 避免使用 jQuery 突出显示所有行和列

html - CSS - 在 div 之外相对于另一个的绝对位置

javascript - 在 Fancybox 中加载 Twitter Tweet 按钮对话框