Programmatically close any open lightbox?

时间:2016-05-17 19:23:28

标签: jquery lightbox

How can I programmatically close any open lightbox ?

I need close the lightbox when the ajax request is finished, any way ?

Using ekko-lightbox

1 个答案:

答案 0 :(得分:3)

在AJAX调用完成时触发事件,让灯箱侦听事件并在看到事件时自行关闭。

// When your AJAX call completes
var event = new CustomEvent('someEventOrSomething');
document.dispatchEvent(event);
// Your lightbox stuff
$(whateverYoureLightboxing).ekkoLightbox({
    onShown: function() {
        var lightbox = this;
        document.addEventListener('someEventOrSomething', function () {
            lightbox.close();
        });
    }
});