可能,实现您想要的唯一方法是获取原始元素并重新打开它。但是将它传递给第二个弹出窗口的close
回调不会给你任何东西,因为它永远不会被调用。MagnificPopup
如果弹出窗口已经打开,则不会触发open
事件,因为实际上只有一个Magnific Popup Object
. 您可以做的是检查是否currItem
等于第一个弹出窗口的项目。
var childOpened,
parentItem,
$parent = $('.ajax-popup-link');
$parent.magnificPopup({
type: 'ajax',
callbacks: {
open: function () {
// triggered only when 1st popup opens
// save 1st popup's item
parentItem = this.currItem;
// will not register new callbacks even if we pass them
$('.image-link').magnificPopup();
},
close: function () {
// will be called twice, since we opened popup twice
// do not move to `afterClose`. `currItem` is not available there
childOpened = (this.currItem !== parentItem);
},
afterClose: function () {
if (childOpened) {
// should be in `afterClose` to avoid conflicts
// with previous popup opening
$parent.magnificPopup('open');
}
}
}
});