开发者

How can I link directly to colorbox from an external link?

开发者 https://www.devze.com 2022-12-28 00:39 出处:网络
I have built a portfolio webpage that uses colorbox to display images. I want to be a开发者_如何学Cble to link directly to the colorbox on that page from an external link sent to people.

I have built a portfolio webpage that uses colorbox to display images. I want to be a开发者_如何学Cble to link directly to the colorbox on that page from an external link sent to people.

Does anyone have any ideas on how I can achieve this?


Ensure that each image link has a unique id, e.g. <a id="photo1" href="photo1.jpg">

Add something like this to your document ready function, after the colorbox init code:

if (location.hash) {
    var link = $(location.hash); // location.hash includes "#" in front
    // change the hasClass() test below to match your image links only
    if (link.length > 0 && link.hasClass('colorbox')) {
        link.click(); // trigger colorbox
    }
}

Then send links with the id appended to the URL, e.g. http://example.com/#photo1

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号