2016-01-19 48 views
0

[情況] 我有關於photoswipe關閉的問題。我有一個HTML頁面A使用Photoswipe進行照片瀏覽。我在頁面A中定義了一個滾動事件。當我打開並關閉photoswipe並返回到我的頁面A時,滾動事件不再有效。如何防止photoswipe解除我的滾動事件?

我的滾動事件:

$(window).scroll(function(){ 
    if ((getDocumentHeight() - getWindowHeight() - getSrollHeight()) == 0) { 
    alert("buttom"); 
    }; 
}); 

我注意到photoswipe的密切和destory方法調用_unbindEvents方法,其執行解除綁定功能。

// Closes the gallery, then destroy it 
close: function() { 
    if(!_isOpen) { 
     return; 
    } 

    _isOpen = false; 
    _isDestroying = true; 
    _shout('close'); 
    _unbindEvents(); 

    _showOrHide(self.currItem, null, true, self.destroy); 
}, 
// destroys gallery (unbinds events, cleans up intervals and timeouts to avoid memory leaks) 
destroy: function() { 
    _shout('destroy'); 

    if(_showOrHideTimeout) { 
     clearTimeout(_showOrHideTimeout); 
    } 

    template.setAttribute('aria-hidden', 'true'); 
    template.className = _initalClassName; 

    if(_updateSizeInterval) { 
     clearInterval(_updateSizeInterval); 
    } 

    framework.unbind(self.scrollWrap, _downEvents, self); 

    // we unbind lost event at the end, as closing animation may depend on it 
    framework.unbind(window, 'scroll', self); 

    _stopDragUpdateLoop(); 

    _stopAllAnimations(); 

    _listeners = null; 
}, 
_unbindEvents = function() { 
    framework.unbind(window, 'resize', self); 
    framework.unbind(window, 'scroll', _globalEventHandlers.scroll); 
    framework.unbind(document, 'keydown', self); 
    framework.unbind(document, 'mousemove', _onFirstMouseMove); 

    if(_features.transform) { 
     framework.unbind(self.scrollWrap, 'click', self); 
    } 

    if(_isDragging) { 
     framework.unbind(window, _upMoveEvents, self); 
    } 

    _shout('unbindEvents'); 
}, 

[問題] 如何防止photoswipe取消綁定我的滾動事件?

回答

0

我有固定的這個問題。

$(document).scroll() 

代替

$(window).scroll() 

它的工作。

0

沒用過photoswipe,但根據評論

// we unbind lost event at the end, as closing animation 'may' depend on it 

如果刪除線會發生什麼?

framework.unbind(window, 'scroll', self); 
+0

我試過這個,但我的滾動事件仍然無法正常工作。並且發生錯誤。 Uncaught TypeError:無法讀取null的屬性'updateScrollOffset' –