문제

I have added colorbox to my site to display my images, but I would like to create an additional link to open the slideshow other than clicking on the image thumbnail. I've tried the code from the FAQ on the Colorbox website, but it is not working. Here is what I have. (link to the webpage: colorbox link demo

<a id="openGallery" href="#">Click for more images</a>
$(document).ready(function() {
    $('a.slideGroup').colorbox({rel:'slideGroup', transition:"elastic", opacity:"0.5"});

    var $gallery = $("a[rel=slideGroup]").colorbox();
    $("a#openGallery").click(function(e){
        e.preventDefault();
        $gallery.eq(0).click();
    });
});
도움이 되었습니까?

해결책

You are calling the colorBox() function twice which I think is incorrect.

If you combine those you should be good to go:

<a id="openGallery" href="#">Click for more images</a>
<script type="text/javascript">
    $(document).ready(function() {
        //just one call to set up the colorbox
        var $gallery = $('a.slideGroup').colorbox({rel:'slideGroup', transition:"elastic", opacity:"0.5"});

        $("a#openGallery").click(function(e){
            e.preventDefault();
            $gallery.eq(0).click();
        });
    });

Here is a working example on CodePen: http://codepen.io/simoncowie/pen/agxGl

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top