Fancybox无法重新打开弹出窗口:未捕获的TypeError:无法读取null的属性“width”

时间:2016-06-29 08:49:34

标签: javascript jquery popup fancybox

使用最新的fancybox和jQuery 2.2.3我试图通过按下“父”弹出窗口中的按钮打开“子”弹出窗口,并在关闭子弹出窗口后重新打开父弹出窗口。

单独弹出窗口打开和关闭就好了。但是当我尝试重新打开父节点时,它会显示一秒钟,然后在控制台中显示一条消息消失:“jquery.fancybox.pack.js:40 Uncaught TypeError:无法读取属性'width'的null”。这恰巧指向了这个:this.overlay.width(a).height("100%");

当我尝试手动重新打开父级时,我看到一个弹出窗口“无法加载请求的内容。请稍后再试。”

我尝试了两种方法,两种方法都失败了

(。fancybox-to-form是父母内部的一个按钮,通过按下你打开的孩子):

1)

$(".fancybox-to-form").on("click", function(){
    var parentPopup = $(this).closest(".wall-popup");

    $.fancybox.open( $("#popup-form"), {        
        afterClose: function(){
            $.fancybox.open( {href: '#wall-popup--1'} );
        }
    } );
});

2)

$(".fancybox-to-form").fancybox({
    afterClose: function(){
        var parentPopup = $(this.element).closest(".wall-popup");
        $.fancybox.open( parentPopup );
    }
});

非常感谢帮助。

1 个答案:

答案 0 :(得分:1)

您可以尝试为第二个fancybox设置setTimeout。 (〜100ms的) 也许第一个fancybox在第二个显示时没有完全关闭。