jQuery / Colorbox - 创建一个单独的链接来打开彩盒?

时间:2009-12-20 23:47:17

标签: jquery colorbox

我正在尝试从其他彩盒图像之外的链接打开jQuery Colorbox。所以,所有的例子都是这样的:

<a href="image1.png" rel="group1"><img src="thumb1.png" /></a>
<a href="image2.png" rel="group1"><img src="thumb2.png" /></a>
<script>$("a[rel='group1']").colorbox();</script>

好的,没关系,但我还需要从单独的链接打开那个颜色框:

<a href="?"> this link should also open the colorbox </a>

我该怎么做才能做到这一点?所有的colorbox示例都只显示了第一个代码块中的内容,而且我不是jQuery专家。

4 个答案:

答案 0 :(得分:20)

这是一个类似于我的项目的东西。

HTML

//I "display:none" the images gallery to hide them...
<div style="display:none;">
 <a href="image1.jpg" rel="example1">Grouped Photo 1</a>
 <a href="image2.jpg" rel="example2">Grouped Photo 2</a>
 <a href="image3.jpg" rel="example3">Grouped Photo 3</a>
</div>

//...then when I click on this JPG image the group of images (above) appear in a colorbox
<img src="circle1.jpg" width="147" height="149" alt="circle" class="circle1" />

这是JQUERY

$(document).ready(function(){

     //when i "click" on the image with a class of "circle1" it opens the "example1" group
     $('.circle1').click(function() {
        $("a[rel='example1']").colorbox({open:true});
     });

});

答案 1 :(得分:5)

啊,想通了!这有效:

将第一个链接更改为:

<a href="image1.png" rel="group1" id="something"><img src="thumb1.png" /></a>

然后,设置我们的额外链接:

<a href="#" onclick="$('#something').colorbox({rel:\'post' . $post->ID . '\', open:true});">click here</a>

答案 2 :(得分:2)

此示例有效,但没有下一个和上一个选择: http://jsfiddle.net/pd6JN/8/

答案 3 :(得分:0)

试试这个:

$(".link-to-click").click(function() {
   $("a.colorbox-link").colorbox({open:true, rel:'colorbox-class-group'});
});