[情况] 关于photoswipe关闭我有问题。我有一个html页面A使用Photoswipe进行照片查看。我在页面A中定义了一个滚动事件。当我打开然后关闭照片并返回到我的页面A时,滚动事件不再起作用。
我的滚动事件:
$(window).scroll(function(){
if ((getDocumentHeight() - getWindowHeight() - getSrollHeight()) == 0) {
alert("buttom");
};
});
我注意到了photoswipe的close和destory方法调用_unbindEvents
方法,它们执行unbind函数。
// 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 :(得分:0)
从未使用过照片,但根据评论
// we unbind lost event at the end, as closing animation 'may' depend on it
如果删除该行会怎样?
framework.unbind(window, 'scroll', self);
答案 1 :(得分:0)
我已经解决了这个问题。
$(document).scroll()
而不是
$(window).scroll()
它正在运作。