ColorBox分组照片

时间:2010-10-15 23:54:04

标签: javascript jquery html colorbox

我使用彩盒,我的工作正常,但我不明白如何在点击时将多个图像添加到图库。

但我需要为每朵花出现2张图片。

感谢您的帮助!

2 个答案:

答案 0 :(得分:7)

这里有很多要解释的因为您使用的是示例代码,您需要在图片代码中添加rel="Example1"属性。每组图像必须具有唯一的rel属性值和相应的jQuery钩子:

您的jQuery代码:

$("a[rel='example1']").colorbox(); // Choose the type of colorbox instance you like and replicate it
$("a[rel='example2']").colorbox();

如果页面上的所有图片都具有相同的rel属性值,则颜色框实例会将您网页上的所有图片分组为幻灯片。

<a href="images/floral/full-size/vegas-weddings-floral-1.jpg" rel="example1" title="Flower 1">
<a href="images/floral/full-size/vegas-weddings-floral-1.jpg" rel="example1" title="Flower 2">
<a href="images/floral/full-size/vegas-weddings-floral-1.jpg" rel="example1" title="Flower 3">

<a href="images/floral/full-size/vegas-weddings-floral-1.jpg" rel="example2" title="Flower 1">
<a href="images/floral/full-size/vegas-weddings-floral-1.jpg" rel="example2" title="Flower 2">
<a href="images/floral/full-size/vegas-weddings-floral-1.jpg" rel="example2" title="Flower 3">

答案 1 :(得分:3)

更好:通过rel或data-rel属性自动分组图像。

<a href=".." class="colorbox" data-rel="group1"><..></a> 
<a href=".." class="colorbox" data-rel="group1"><..></a> 
<a href=".." class="colorbox" data-rel="group2"><..></a> 
<a href=".." class="colorbox" data-rel="group2"><..></a> 
<a href=".." class="colorbox" data-rel="group2"><..></a> 

配置colorbox - 使用rel property的回调

$('.colorbox').colorbox({
    rel:function() {        
        return $(this).data('rel');
    }
});

(修复了jquery类选择器上的拼写错误)