也許,實現你想要的唯一方法就是取原始元素並重新打開它。但傳遞給第二彈出的close
回調不會給你任何東西,因爲它永遠不會被調用。如果popup已經打開,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');
}
}
}
});