jquery
  • colorbox
  • 2009-12-20 80 views 7 likes 
    7

    我试图从其余的colorbox图像之外的链接打开jQuery Colorbox。因此,所有的例子是这样的:jQuery/Colorbox - 创建一个单独的链接来打开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> 
    

    OK,没问题,但我还需要从一个单独的链接打开颜色框:

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

    什么我必须把哪里去做?所有的colorbox示例都显示了第一个代码块中的内容,我不是jQuery专家。

    回答

    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> 
    
    +1

    您应该在document.ready函数中添加您的colorbox函数调用,而不是onclick。 – 2011-05-27 01:32:22

    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}); 
        }); 
    
    }); 
    
    2

    这个例子的工作原理,但没有一个和以前的选择: http://jsfiddle.net/pd6JN/8/

    0

    试试这个:

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