Jquery lightbox 不适用于 AdGallery
我使用 AdGallery 创建图像库(遵循此插件: http ://coffeescripter.com/2009/07/ad-gallery-a-jquery-gallery-plugin/)。
和 Jquery lightbox : http://leandrovieira.com/projects/jquery/lightbox/
现在我想要这个,当用户单击大图像时,会出现一个灯箱。所以我修改了 jquery.ad-gallery.js 中的几行代码:
from
if(image.link) {
var link = $('<a rel="lightbox" href="'+ image.link +'" target="_blank"></a>');
link.append(img);
img_container.append(link);
} else {
img_container.append(img);
}
到
if(image.link) {
var link = $('<a rel="lightbox" href="'+ image.link +'" target="_blank"></a>');
link.append(img);
img_container.append(link);
} else {
var link = $('<a href="'+ image.image +'" rel="lightbox" class="lightbox"></a>');
link.append(img);
img_container.append(link);
}
但是当我点击大图时,什么也没有发生。
我的 html 中确实有这些代码:
$(function() {
$('#gallery a').lightBox();
});
我在这里缺少什么?
Im using AdGallery for creating an image gallery (following this plugin : http://coffeescripter.com/2009/07/ad-gallery-a-jquery-gallery-plugin/).
And Jquery lightbox : http://leandrovieira.com/projects/jquery/lightbox/
Now I want this, when user click on the large image, a lightbox appears. So I modified some lines of code in jquery.ad-gallery.js:
from
if(image.link) {
var link = $('<a rel="lightbox" href="'+ image.link +'" target="_blank"></a>');
link.append(img);
img_container.append(link);
} else {
img_container.append(img);
}
to
if(image.link) {
var link = $('<a rel="lightbox" href="'+ image.link +'" target="_blank"></a>');
link.append(img);
img_container.append(link);
} else {
var link = $('<a href="'+ image.image +'" rel="lightbox" class="lightbox"></a>');
link.append(img);
img_container.append(link);
}
But when I click on the large image, nothing happened.
I did have these code in my html:
$(function() {
$('#gallery a').lightBox();
});
What was I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
而不是:
使用:
这可以防止 lightbox 向 div 中的其他图形显示“下一个”选项并产生奇怪的结果,并防止 lightbox 附加到缩略图。
因为当您更改图像时,ad-gallery 会刷新广告图像 div 内容,因此还要
在 jquery.ad-gallery.js 中的 _showWhenLoaded: 函数末尾添加,以便在选择每个图像时将 lightbox 事件附加到每个图像。
Instead of:
Use:
This prevents lightbox from showing a 'Next' option to other graphics in the div with strange results and prevents lightbox from getting attached to the thumbnails.
Because ad-gallery flushes the ad-image div contents when you change images, also add
at the end of the _showWhenLoaded: function in jquery.ad-gallery.js so that the lighbox event gets attached to each image when it's selected.
我本人是费了很大的劲才做到这一点的。
这个想法是幻灯片中的主图像弹出到大型灯箱弹出窗口。
要解决的问题是:
lightbox 查找现有元素并生成图像数组,但这里我们一次只有一个动态项目可以处理。
我们希望 lightbox 找到的动态元素是动态的,因此我们需要使用一些动态 jQuery 方法而不是默认方法。
我们希望 Lightbox 了解幻灯片中的所有图像,即使它只能找到一张主图像。
我们希望灯箱能够找到与图像相关的文本。
解决方法:
确保将大弹出窗口的路径放在拇指的 longdesc 属性中,这样 ad-gallery 会将它们放在幻灯片图像周围的 href 属性中,并且 lightBox 会找到它们
使用 ad- 中的回调图库为每张幻灯片调用灯箱加载。
此工作的示例如下:
http://www.vikingkayaks.co。 nz/shop/kayaks?product=1
但请注意,此示例中还有其他复杂的内容,因此我尝试提取上述描述中的重要部分。
I myself got this working with great difficulty.
The idea being that the main image in the slideshow popups to the large lightbox popup.
The issues to solve are:
lightbox looks for existing elements and makes an image array, but here we only have one dynamic item to work on at a time.
The dynamic element we want lightbox to find is dynamic, so we need to use some dynamic jQuery method rather than the default method.
We want lightbox to know about all the images in the slideshow even though it will only find one main image.
We want lightbox to find the text associated with the images.
To solve:
Make sure you are putting the path to the big popups in the longdesc attribute of the thumbs, that way ad-gallery will put them in the href attribute around the slide image, and lightBox will find them
Use the callbacks in ad-gallery to call a lightbox load for every slide.
An example of this working is found here:
http://www.vikingkayaks.co.nz/shop/kayaks?product=1
but note there are other complex things in this example, so I have tried to distil the important parts in the description above.