admin管理员组文章数量:1290938
I'm using the Lightbox2 script and the content of my page is loaded via an AJAX request.
I don't find any function to attach new images or initialize Lightbox2 after an AJAX request, How can I make that in order to use Lightbox2 for images loaded via AJAX ?
Léo
I'm using the Lightbox2 script and the content of my page is loaded via an AJAX request.
I don't find any function to attach new images or initialize Lightbox2 after an AJAX request, How can I make that in order to use Lightbox2 for images loaded via AJAX ?
Léo
Share Improve this question asked Jul 20, 2014 at 9:40 leoswleosw 1051 gold badge2 silver badges6 bronze badges 02 Answers
Reset to default 9I had to reinitialize lightbox in order to detect new images. I have done that like this:
window.lightbox.init();
I placed this code in my success handler of ajax call after I have added the new content:
contentContainer.empty().html(data);
From the documentation files: http://lokeshdhakar./projects/lightbox2/
You do not need to initiate anything, any image link with the data-lightbox
attribute like this:
<a href="img/image-1.jpg" data-lightbox="image-1" data-title="My caption">Image #1</a>
will work automagically even if loaded by AJAX as soon as you add it to your DOM.
EDIT: After having taken a look at the lightbox script, you may have to change as well the line #51:
$('body').on('click', 'a[rel^=lightbox], area[rel^=lightbox], a[data-lightbox], area[data-lightbox]', function(event) {
into this:
$('body').live('click', 'a[rel^=lightbox], area[rel^=lightbox], a[data-lightbox], area[data-lightbox]', function(event) {
本文标签: javascriptAJAX loaded content with lightbox2Stack Overflow
版权声明:本文标题:javascript - AJAX loaded content with lightbox2 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741508586a2382469.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论