3

我正在使用手动颜色框调用,如下所示:

$('a[rel="example1"]').click(function(event){

                    event.preventDefault();

                    $.colorbox({
                        href: $(this).attr('href'),
                        maxWidth: '90%',
                        initialWidth: '200px',
                        initialHeight: '200px',
                        speed: 700,
                        overlayClose: false
                    });
                });

我必须以这种方式使用它,以免干扰另一个插件(这是我让它工作的唯一方法)。

问题是,当模态弹出时,它没有组中的其他图像或锚点,因此没有“下一个”或“上一个”选项。

有想法该怎么解决这个吗?

4

3 回答 3

3

您可以在调用 colorbox 时手动设置rel要组合在一起的元素:

$('a[rel="example1"]').click(function(event){

    event.preventDefault();

    $.colorbox({
        href: $(this).attr('href'),
        maxWidth: '90%',
        initialWidth: '200px',
        initialHeight: '200px',
        speed: 700,            
        overlayClose: false,
        rel: $(this).attr('rel')
    });
});

编辑

我在彩盒源中进行了更多挖掘,它不起作用的原因是因为共享相同内容的其他链接rel没有为它们创建关联的彩盒对象。以下工作,但它不是一个漂亮的黑客......它可能无法解决您的其他插件问题:

$('a[rel="example1"]').click(function(event){

    event.preventDefault();

    // Build up the list of related colorbox objects
    $('a[rel="example1"]').colorbox({
        maxWidth: '90%',
        initialWidth: '200px',
        initialHeight: '200px',
        speed: 700,            
        overlayClose: false
    });

    // Open the specific link's colorbox
    $.colorbox({
        href: $(this).attr('href')
    });
});
于 2010-07-22T18:23:37.143 回答
3

我在点击时创建 jQuery colorbox 的解决方案:

$(function(){
    $('#some-images-container a[rel="gallery"]').live('click', function(){
        var $this = $(this);
        var rel = $this.attr('rel');

        // Build colorbox sequence
        $this.closest('div') // parent container
            .find('a[rel="'+rel+'"]').colorbox({ // find all matching items & init colorbox on them
                    open: false, // don't open, just init
                    rel: rel // use the rel
                }
        });

        // Open the specific link's colorbox
        $this.colorbox({open: true});
        return false; // prevent
    });
});
于 2012-05-09T01:00:02.803 回答
0

唯一的问题是您没有为颜色框设置rel属性。

于 2010-07-22T18:25:21.250 回答