Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I prevent photoswipe to unbind my scroll event? #1059

Open
huanxijiuhao opened this issue Jan 19, 2016 · 7 comments
Open

How can I prevent photoswipe to unbind my scroll event? #1059

huanxijiuhao opened this issue Jan 19, 2016 · 7 comments

Comments

@huanxijiuhao
Copy link

[situation]
I have problems about photoswipe close. I have a html page A using Photoswipe for a photo view. 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.

My scroll event:

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

I noticed photoswipe's close and destory method, which executes the unbind function.

// 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');
},
@dimsemenov
Copy link
Owner

Please provide a reduced test case (isolated example) that reproduces the problem.

You may create it based on CodePens in PhotoSwipe documentation: raw gallery, gallery with thumbnails, custom HTML content in slides. If you're not comfortable with CodePen, you may export code via Export -> Export .zip, and upload test case to your server.

@cireme
Copy link

cireme commented Feb 5, 2016

Hi,

I have the same issue here.

I'm also using jQuery in my code.

After closing PhotoSwipe, the scroll I binded on the window isn't throwing the scroll event anymore. I tried to rebind the scroll event but it's not doing anything, the window scroll seems to just be dead (or prevented somehow). And then when I call the scrollTop function, it's always returning 0.

I created a codepen (http://codepen.io/anon/pen/YwJqeB), but I can't reproduce the problem inside it. It's driving crazy me ^^

@dimsemenov
Copy link
Owner

@cireme, remove all js/css not related to PhotoSwipe from the page where you get the problem, and link to it (or attach to message), and I might help.

I can not assist you without a reduced test case.

@zzyds
Copy link

zzyds commented Feb 11, 2016

i have the same problem. when photoswipe is open and close it. so the $(window).on("scroll",fun...);isnt work.

i cant to findout someone options of event to prevent it .

@cireme
Copy link

cireme commented Feb 12, 2016

@dimsemenov Hey, thanks for the answer. I understand. I'll see if I have time to rollback on the code to get to the state where it isn't working.

But I've been working on the problem on my side by debugging the plugin and I don't get where the problem comes from.

@lpsm The solution I choose on my app was to add a wrapper on the whole page and handle my page scroll on it, so I don't interact at all with the window and PS's binding anymore.

@huanxijiuhao
Copy link
Author

@lpsm @cireme
Hey, I solve this problem by using $(document).on("scroll",fun...); instead of $(window).on("scroll",fun...);. It's not a good solution, but it's working.

@zzyds
Copy link

zzyds commented Mar 18, 2016

yeah! thank to @huanxijiuhao you are right! thats work well .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants