[英]How to reinitialize the lightgallery after ajax call
我正在使用 lightgallery 插件在點擊時顯示我網站的圖像。 我將燈光畫廊初始化為
$(document).ready(function(){
$('#lightgallery').lightGallery({
selector: '.item'
});
});
在文檔加載它的工作正常。 問題是當我加載更多圖像並使用 jquery 附加它們時,我想再次重新初始化 lightgallery 以便為 ajax 調用加載的圖像工作。 但是燈廊對他們不起作用。 它僅適用於頁面加載時加載的圖像。
這可能會有所幫助:
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();
}
});
這是我在 ajax 中有效的答案
成功:函數(){
//destroy your lightgallery
try{ $('#lightgallery').lightGallery(); $('#lightgallery').data('lightGallery').destroy(true); }catch(ex){};
//and then re-initiate gallery again
$('#lightgallery').lightGallery({
selector: '.item'
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.