获取灯箱(或其替代品)以在单击链接时动态显示图库
注意:我已经使用了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您必须对通过 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:
所以你可以这样做:
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:So you can just do this: