2010-07-22 67 views
3

我使用手动颜色框呼叫,像这样初始化画廊:jQuery的颜色框:在点击

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

        event.preventDefault(); 

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

我不得不使用它,为了不与其它插件干扰这种方式(这是唯一的方法,我可以让它工作)。

问题是,当模式弹出时,它没有组中的其他图像或锚点,所以没有“下一个”或“前一个”选项。

有关如何解决此问题的任何想法?

回答

3

您可以手动设置要分组元素的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的其他链接尚未为其创建关联的colorbox对象。下面的作品,但它不是一个漂亮的劈...它可能不会在你的其他插件的问题得到:

$('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') 
    }); 
}); 
+0

我猜想,将工作,但我尝试过了,它没有。即使在下载中包含的示例页面中,它也不起作用(如果我使用手动呼叫)。 – Matthew 2010-07-22 18:36:07

+0

@Matthew:看看我的编辑黑客绕过它。上面的例子在colorbox源代码中提供了示例。 – Pat 2010-07-22 19:43:15

+0

完美。非常感谢。它在示例之一上工作,只有一件事我不得不改变,所以它不会干扰另一个插件(出于某种原因,组中的第一个图像/模式被计数两次)。 – Matthew 2010-07-22 22:09:37

0

唯一的问题是,你没有设置相对属性为彩盒。

3

我上点击创建jQuery的颜色框的解决方案:

$(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 
    }); 
});