销毁灯廊并重新启动它会导致问题
Destroying a light gallery and re initiating it causing issue
我有一个 div,ID 为 "tempPictures"。我想销毁画廊并在关闭然后重新打开时重新启动它。第一次点击时它工作正常,但第二次,它在同一个选项卡中打开图像而不是 light Gallery。有人遇到过这样的问题吗?
function getReplyImages(id) {
$formData = {
"_token": $token,
"inmate_reply_id": id
}
ajaxStartStop();
$.ajax({
url: $inmateReplyAttachmentsRoute,
type: 'POST',
data: $formData,
success: function (data) {
var html = '';
Object.keys(data).forEach(function (key) {
html += '<a href="' + data[key].file + '">';
html += '<img src="' + data[key].thumnail + '" />';
html += '</a>';
});
$('#tempPictures').html(html);
if(!$galleryLoaded) {
console.log('loaded');
$('#tempPictures').lightGallery({thumbnail: true});
$('#tempPictures > a:first > img').trigger('click');
}
$galleryLoaded = true;
},
error: function ($error) {
notificationMsg($error, error);
}
});
}
$(function () {
$("#tempPictures > a:first > img").click(function () {
return false;
});
});
$('#tempPictures').on('onCloseAfter.lg',function(event, index, fromTouch, fromThumb){
$('#tempPictures').lightGallery({destroy: true});
$('#tempPictures').html('');
$galleryLoaded = false;
});
我明白了。我没有正确地破坏灯廊。原来是这样。
$('#tempPictures').data('lightGallery').destroy(true);
我有一个 div,ID 为 "tempPictures"。我想销毁画廊并在关闭然后重新打开时重新启动它。第一次点击时它工作正常,但第二次,它在同一个选项卡中打开图像而不是 light Gallery。有人遇到过这样的问题吗?
function getReplyImages(id) {
$formData = {
"_token": $token,
"inmate_reply_id": id
}
ajaxStartStop();
$.ajax({
url: $inmateReplyAttachmentsRoute,
type: 'POST',
data: $formData,
success: function (data) {
var html = '';
Object.keys(data).forEach(function (key) {
html += '<a href="' + data[key].file + '">';
html += '<img src="' + data[key].thumnail + '" />';
html += '</a>';
});
$('#tempPictures').html(html);
if(!$galleryLoaded) {
console.log('loaded');
$('#tempPictures').lightGallery({thumbnail: true});
$('#tempPictures > a:first > img').trigger('click');
}
$galleryLoaded = true;
},
error: function ($error) {
notificationMsg($error, error);
}
});
}
$(function () {
$("#tempPictures > a:first > img").click(function () {
return false;
});
});
$('#tempPictures').on('onCloseAfter.lg',function(event, index, fromTouch, fromThumb){
$('#tempPictures').lightGallery({destroy: true});
$('#tempPictures').html('');
$galleryLoaded = false;
});
我明白了。我没有正确地破坏灯廊。原来是这样。
$('#tempPictures').data('lightGallery').destroy(true);