dimsemenov / PhotoSwipe

JavaScript image gallery for mobile and desktop, modular, framework independent
http://photoswipe.com
MIT License
24.18k stars 3.31k forks source link

v5 API docs #1815

Open goldmerc opened 3 years ago

goldmerc commented 3 years ago

When do you plan to write the API docs for v5?

Specifically, I need to listen to when the image changes and get the index of the new image.

Many thanks!

goldmerc commented 3 years ago

Looking at the code, I think this would work...

photoswipe.on('afterGoto', () => {
    this.index = photoswipe.index;
});
lnfel commented 2 years ago

H, just to add more info to this. We can also listen to change event. By default afterGoto event only listens to slide change that was initiated by next and prev arrow buttons. The change event listener on the other hand listens to slide drag and keyboard initiated changes:

photoswipe.on('change', () => {
    // do something here
});

Also I found the current index at: photoswipe.pswp.currIndex and photoswipe.pswp.currSlide.index

rothos commented 9 months ago

@lnfel Thank you! Was trying to find out how to get the current index and you saved me having to dig through the source code. I didn't see it anywhere in the docs.