2017-04-23 120 views
0

我正在使用jQuery的PhotoSwipe插件。如何讓用戶在顯示photoswipe畫廊時點擊鏈接?

我的網站使用一個固定的菜單,當用戶向下滾動。

隨着z-index的我沒能做出photoswipe畫廊重疊我的菜單。所以我調整了默認的photoswipe窗格大小,以便爲菜單騰出空間。我也喜歡這種外觀。

現在,當我打開一張照片,但是不是導向與PhotoSwipe的其他頁面,PhotoSwipe的一些回調呈現給用戶重定向到他來自哪裏。

如果我使用破壞回撥photoswip,並把警報在裏面,這延遲的重定向(返回到用戶來自的頁面)。

我怎麼能允許用戶關閉photoswipe畫廊,而不被重定向?

編輯: 這是我如何初始化photoswipe畫廊。

function showSoftwareGallery(sections, index){ 
    var pswpElement = document.querySelectorAll('.pswp')[0]; 

    var items = new Array(sections.length); 
    for(var i=0; i<sections.length; i++){ 
     items[i] = { 
      src: sections[i].image, 
      w: 1920, 
      h: 1080, 
     }; 
    } 

// define options (if needed) 
    var options = { 
     // optionName: 'option value' 
     // for example: 
     index: index, // start at first slide 
     escKey: true, 
     arrowKeys: true, 
     shareEl: false, 
     closeEl:true, 
     captionEl: true, 
     fullscreenEl: true, 
     zoomEl: true, 
    }; 

// Initializes and opens PhotoSwipe 
    var headerHeight = $('nav').first().height(); 
    var height = $(window).height() - headerHeight; 
    $('.pswp').first().css('height', height + 'px'); 
    $('.pswp').first().css('top', headerHeight + 'px'); 
    var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options); 


    gallery.listen('destroy', function() { alert('destroy')}); 


    gallery.init(); 
} 

編輯2 你在這裏看到我的photoswipe顯示的屏幕截圖。它顯示我的主菜單仍然可見,用戶可以點擊它。 enter image description here

+0

你填充項目變量?發佈代碼初始化並調用photoswipe。 –

+0

我編輯了這個問題。謝謝。 –

+0

那麼這些都是我用photoswipe發現的問題:不正確的項目變量,javascript錯誤(在這種情況下,圖像在該選項卡中打開)。你可能還有的問題是菜單被點擊並將用戶帶到某個地方?老實說,我不知道你的意思是什麼:'現在當我打開一張照片,但是用PhotoSwipe導航到另一個頁面時,PhotoSwipe的一些回調似乎將用戶重定向到他來自哪裏。「你怎麼能使用photoswipe導航到其他頁面?重定向用戶在哪裏?用戶來自哪裏? –

回答

1

src/js/history.js文件包含以下代碼:

 _listen('destroy', function() { 
      if(!_hashReseted) { 
       returnToOriginal(); 
      } 
     }); 

您沒有提供可重複的代碼,所以這是不是100%,但應該是有幫助的。我的代碼改成這樣:

 _listen('destroy', function() { 
      if(!_hashReseted && !myApp.shouldClosePhotoswipe) { 
       returnToOriginal(); 
      } 
     }); 

在您的應用程序添加以下代碼:

var myApp = { 
    // mix in with your javascript code 
    shouldClosePhotoswipe: false 
} 

,並點擊菜單時去的地方只需添加這行:

myApp.shouldClosePhotoswipe = true; 

然後你需要重建dist/photoswipe.js文件。
您也可以直接編輯0​​文件。