获取灯箱(或其替代品)以在单击链接时动态显示图库

发布于 2024-12-07 11:39:40 字数 636 浏览 1 评论 0原文

注意:我已经使用了 lightbox 及其许多替代方案来尝试解决此问题,目前我正在使用clearbox。

问题:目前我有 JavaScript 代码,根据单击的元素,灯箱的模式弹出窗口应该向用户显示一组不同的图像。下面是我目前正在修改的代码。

$("download").html(" \
<span style='color:white'> \
    <a href='img/26.jpg' rel='clearbox' title='Caption'>View Screenshots</a> \
</span><br /> \

然而,该链接不会启动灯箱(适用于页面上已有的链接),我花了两天时间浏览谷歌和 stackoverflow 试图找到解决方案。

我想要实现的目标概述:我的作品展示,其中一张图像将根据所选作品通过 javascript 作为超链接动态添加。当用户单击时,他们将可以浏览所有其他隐藏但属于图库的图像。将会有多个画廊。感谢您的阅读。

编辑1:请原谅mspaint工作 https://i.sstatic.net/rN8q1.jpg

Note: I have used lightbox and its many alternatives in an attempt to fix this and im using clearbox at the moment.

The Problem: Currently i have javascript code that depending on the element that is clicked, the modal popup of the lightbox should show the user a different set of images. Below is the code I am currently modifying.

$("download").html(" \
<span style='color:white'> \
    <a href='img/26.jpg' rel='clearbox' title='Caption'>View Screenshots</a> \
</span><br /> \

However the link does not initiate the lightbox (works on links already on the page) and i have spent two days looking through google and stackoverflow trying to find a fix.

Outline of what I am trying to achieve: A Showcase of my work where one image will be dynamically added through javascript as a hyperlink depending on the work chosen. When the user clicks it will allow them to go through all the other images that are hidden but part of the gallery. There will be multiple galleries. Thank you for reading.

Edit 1: Please excuse the mspaint job
https://i.sstatic.net/rN8q1.jpg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千と千尋 2024-12-14 11:39:41

问题是您必须对通过 ajax 拉入页面的任何链接调用clearbox。当您最初调用clearbox时,jQuery会从选择器中获取所有元素并向它们添加功能。然后,如果您通过 ajax 拉入其他链接(或者甚至稍后将它们添加到 dom),那么这些元素的clearbox 尚未实例化。

jQuery .live() 函数修复了添加到 dom 的元素的此问题,但clearbox 并不是为使用 .live() 而构建的。因此,您必须对单独添加到页面的任何其他链接调用clearbox。

http://api.jquery.com/live/


编辑
我快速浏览了clearbox文档页面:http://www.clearbox.hu/index_en。 html

它指出您可以调用 CB_Init() 为新项目添加clearbox:

通过 AJAX 使用脚本
如果您使用 AJAX 加载新内容
网页无需刷新,您希望 Clearbox 可以工作
对于新内容,您也必须调用 CB_Init();之后函数
您的 AJAX 内容加载。

所以你可以这样做:

$("download").html(" \
        <span style='color:white'> \
           <a href='img/26.jpg' rel='clearbox' title='Caption'>View Screenshots</a> \
        </span><br /> \ ");
CB_Init();

The issue is that you have to call clearbox on any links that are pulled into the page via ajax. When you call clearbox initially, jQuery grabs all of the elements from your selector and adds the functionality to them. If you then, pull in additional links via ajax (or even add them to the dom later), then clearbox has not been instantiated for those elements.

The jQuery .live() function fixes this for elements added to the dom, but clearbox is not built to use .live(). Therefore, you'll have to call clearbox on any additional links that are added to the page separately.

http://api.jquery.com/live/


EDIT
I've had a quick look at the clearbox doc page: http://www.clearbox.hu/index_en.html

It states that you can call CB_Init() to add clearbox to new items:

Using the script with AJAX
If you load new content with AJAX in your
webpage without refreshing it and you want, that the clearbox work
with the new content too, you have to call CB_Init(); function AFTER
your AJAX content-load.

So you can just do this:

$("download").html(" \
        <span style='color:white'> \
           <a href='img/26.jpg' rel='clearbox' title='Caption'>View Screenshots</a> \
        </span><br /> \ ");
CB_Init();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文