admin管理员组文章数量:1333442
I am using lightgallery plugin to display images of my website on click. I initialized the light gallery as
$(document).ready(function(){
$('#lightgallery').lightGallery({
selector: '.item'
});
});
At the document load its working fine. The problem is when i am loading more images and appending them using jquery i want to reinitialize the lightgallery again to work for the iamges loaded by ajax call. But the lightgallery is not working for them. It is working only for the images which are loaded at the time of page loading.
I am using lightgallery plugin to display images of my website on click. I initialized the light gallery as
$(document).ready(function(){
$('#lightgallery').lightGallery({
selector: '.item'
});
});
At the document load its working fine. The problem is when i am loading more images and appending them using jquery i want to reinitialize the lightgallery again to work for the iamges loaded by ajax call. But the lightgallery is not working for them. It is working only for the images which are loaded at the time of page loading.
Share Improve this question asked Oct 14, 2016 at 8:16 Deepak KishoreDeepak Kishore 1381 silver badge9 bronze badges 3- Please add the code where you load more images – Rory McCrossan Commented Oct 14, 2016 at 8:20
- 1 can you make a fiddle? – Adrian C. Commented Oct 14, 2016 at 8:21
- 1 checkout this! Its might help you. codepen.io/sachinchoolur/details/QjLNMM – Balasubramanian Commented Oct 14, 2016 at 8:26
2 Answers
Reset to default 6This might help:
function createLightGallery()
{
$('#lightgallery').lightGallery({
selector: '.item'
});
}
// on document load
$(document).ready(function(){
createLightGallery();
});
// on the AJAX request
$.ajax({
url: "/get_images",
.
.
success: function()
{
if("#lightgallery").data("lightGallery"))
$("#lightgallery").data("lightGallery").destroy(true);
createLightGallery();
}
});
This is my answer that works in ajax
success: function() {
//destroy your lightgallery
try{ $('#lightgallery').lightGallery(); $('#lightgallery').data('lightGallery').destroy(true); }catch(ex){};
//and then re-initiate gallery again
$('#lightgallery').lightGallery({
selector: '.item'
});
}
本文标签: javascriptHow to reinitialize the lightgallery after ajax callStack Overflow
版权声明:本文标题:javascript - How to reinitialize the lightgallery after ajax call - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742354524a2459148.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论