1

我有一个 id 为“tempPictures”的 div。我想销毁画廊并在关闭然后重新打开时重新启动它。第一次单击时它工作正常,但第二次,它会在同一选项卡中打开图像,而不是轻图库。Any1遇到过这样的问题吗?

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;
});
4

1 回答 1

1

我得到了它。我没有正确地破坏光廊。必须这样做。

$('#tempPictures').data('lightGallery').destroy(true);
于 2018-01-25T06:01:57.060 回答