【问题标题】:Multiple Fancybox 2 Galleries issue with "rel"多个 Fancybox 2 画廊问题与“rel”
【发布时间】:2013-06-10 20:38:19
【问题描述】:

我看到了一些解决类似问题的问题,但似乎没有一个修复程序适用于我的情况。基本上我在整个网站的一个页面上有多个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>

谢谢!

【问题讨论】:

    标签: jquery html fancybox gallery fancybox-2


    【解决方案1】:

    这部分代码:

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

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

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

    ...你会没事的。

    【讨论】:

    • 顺便说一句,我有fancybox 2.1.5,而不是使用“rel”,它现在检查“data-fancybox-group”属性。我需要逐步浏览他们的实际代码才能找到它。您可以覆盖要与(当前未记录的)groupAttr 选项一起使用的属性名称。例如,要将其改回 rel,您将拥有 {groupAttr: "rel"} github.com/fancyapps/fancyBox/issues/288
    • @GregoryMagarshak : Fancybox 2.x 实际上检查reldata-fancybox-group。出于验证目的,最好使用第二个。我大约在 2 年前回答了这个问题;)stackoverflow.com/a/9037826/1055987
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-09
    • 1970-01-01
    • 2012-02-26
    相关资源
    最近更新 更多