2013-09-24 108 views
0

我有一個相當基本設置:Magnific Popup - 在彈出窗口中彈出。如何使「關閉」轉到上一個彈出窗口?

$('.ajax-popup-link').magnificPopup({ 
     type: 'ajax', 
     callbacks: { 
      ajaxContentAdded: function() { 
       $('.image-link').magnificPopup(); 
      }; 
     } 
}); 

我想要做的就是有「圖像鏈接」彈出窗口的關閉事件回到原來的彈出窗口。我的第一個想法是抓住原始元素,並可能將它傳遞到第二個彈出窗口,然後將close事件綁定到該元素...以便在關閉時自動彈出原始元素。

有沒有其他人做過這樣的事情?有沒有更好的方法可能做到這一點?

回答

1

也許,實現你想要的唯一方法就是取原始元素並重新打開它。但傳遞給第二彈出的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'); 
      } 
     } 
    } 
}); 
相關問題