2

我已经看到一些解决类似问题的问题,但似乎没有一个修复程序适用于我的情况。基本上我在整个网站的一个页面上有多个fancybox画廊,当点击网站上的一个幻灯片时,它会从一个画廊继续到下一个。我希望画廊/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>

谢谢!

4

1 回答 1

1

这部分代码:

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

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

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

......你会没事的。

于 2013-06-10T23:06:05.437 回答