简体   繁体   English

如何防止Photowipe取消绑定滚动事件?

[英]How can I prevent photoswipe to unbind my scroll event?

[ situation ] I have problems about photoswipe close. [ 情况 ]我有关于光刷关闭的问题。 I have a html page A using Photoswipe for a photo view. 我有一个HTML页A,使用Photoswipe进行照片查看。 I have defined a scroll event in page A. When I open and then close photoswipe and go back to my page A, the scroll event is not working any more. 我在页面A中定义了一个滚动事件。当我打开然后关闭photowipe并返回到页面A时,该滚动事件不再起作用。

My scroll event: 我的滚动事件:

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

I noticed photoswipe's close and destory method call _unbindEvents methods, which executes the unbind function. 我注意到photowipe的close和_unbindEvents方法调用_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');
},

[ question ] How can I prevent photoswipe to unbind my scroll event? [ 问题 ]如何防止照片擦除解除绑定滚动事件?

Never used photoswipe, but according to the comment 从未使用过光刷,但根据评论

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

what happens if you remove the line? 如果删除该行会发生什么?

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

I have fixed this problem. 我已经解决了这个问题。

$(document).scroll() 

instead of 代替

$(window).scroll() 

It's working. 工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM