2

我懂了:

$(document).ready(function(){
    $(".top_up").colorbox(
        {
            rel:'group3',
            opacity: '0.2'

        }
        );
});

然后用这个:

<a id="172703536171203_661714" class="top_up" rel="pics" href="FULL_IMAGE_LINK" title=""><img src='THUMBNAIL' style='border: medium solid #1A1A1A;' /></a>

工作得很好..

但我希望 href="" 不是完整的图像链接,并让颜色框在 rel 属性或其他内容中查找完整的图像链接(没关系,除了 href 和 id 属性之外)。

我怎样才能做到这一点?

4

1 回答 1

7

你已经有99%了。但是,rel除了使用属性,您还可以使用自定义数据属性,使代码更具可读性:

<a data-colorbox-href="http://...">
    <img ... />
</a>

然后使用颜色框实例化中的“href”选项,使用回调data-colorbox-href从单击的链接中获取(或其他)的值:

$(".top_up").colorbox({
    //all the other options you have up there, plus...
    href: function() {
        return $(this).attr("data-colorbox-href");
    }
});
于 2012-09-11T19:42:41.613 回答