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

Scroll last element into view when zoom out #2099

Open
josobrate opened this issue May 1, 2024 · 3 comments
Open

Scroll last element into view when zoom out #2099

josobrate opened this issue May 1, 2024 · 3 comments

Comments

@josobrate
Copy link

josobrate commented May 1, 2024

Is it possible to scroll the last element into view when zooming out?

This would be helpful in a large gallery.

e. g. if you swipe through 50 of 100 images and zoom out, you have to start from the beginning or scroll through the images and find the last one you've viewed.

Scrolling the last element into view when zooming out would help very much.

@josobrate josobrate changed the title Scroll to last element when zoom out Scroll last element into view when zoom out May 1, 2024
@dimsemenov
Copy link
Owner

Yes, you can do something like:

pswp.on('close', () => {
  if (pswp.currSlide.data.element) pswp.currSlide.data.element.scrollIntoView();
});

@josobrate
Copy link
Author

Works like a charm, thank you so much for your quick answer <3

@noisefloordev
Copy link

This is what I'm using:

        this.photoSwipe.on("change", () => {
            let pswp = this.photoSwipe.pswp;
            if(pswp.currSlide && !this.photoSwipe.pswp.opener.isOpening)
                pswp.currSlide.data.element.scrollIntoView({ behavior: "instant" });
        });

Doing it in change makes sure it's ready before the gallery becomes visible, and the isOpening check is so it doesn't scroll the view when entering, only when exiting. (That's an internal interface, but simpler than tracking it myself.) "instant" makes sure it doesn't trigger a smooth scroll animation, since this is meant to happen offscreen.

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

3 participants