从href属性以外的其他内容加载colorbox图像

Kar*_*rem 2 jquery colorbox

我懂了:

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

        }
        );
});
Run Code Online (Sandbox Code Playgroud)

然后用这个:

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

工作得很好..

但我希望href =""不是完整的图像链接,而是让colorbox在rel属性或其他内容中查找完整的图像链接(无关紧要,只是href和id属性).

我怎样才能做到这一点?

Don*_*ghn 7

你已经99%了.但是,rel您可以使用自定义数据属性,而不是使用该属性,从而使代码更具可读性:

<a data-colorbox-href="http://...">
    <img ... />
</a>
Run Code Online (Sandbox Code Playgroud)

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

$(".top_up").colorbox({
    //all the other options you have up there, plus...
    href: function() {
        return $(this).attr("data-colorbox-href");
    }
});
Run Code Online (Sandbox Code Playgroud)