Open josobrate opened 2 months ago
Yes, you can do something like:
pswp.on('close', () => {
if (pswp.currSlide.data.element) pswp.currSlide.data.element.scrollIntoView();
});
Works like a charm, thank you so much for your quick answer <3
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.
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.