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

Kei*_*Jr. 7 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>
Run Code Online (Sandbox Code Playgroud)

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

<a href="?"> this link should also open the colorbox </a>
Run Code Online (Sandbox Code Playgroud)

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

Chr*_*one 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" />
Run Code Online (Sandbox Code Playgroud)

这是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});
     });

});
Run Code Online (Sandbox Code Playgroud)


Kei*_*Jr. 5

啊,想通了!这有效:

将第一个链接更改为:

<a href="image1.png" rel="group1" id="something"><img src="thumb1.png" /></a>
Run Code Online (Sandbox Code Playgroud)

然后,设置我们的额外链接,如下所示:

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