Search code examples
javascriptphotoswipe

How can I make PhotoSwipe work in different directions?


I mean, normal actions of PhotoSwipe is to scroll horizontally and to close after vertical swipe. I would like to switch actions so it scrolls vertically and closes after horizontal swipe.

Does anyone know how to do that?


Solution

  • You'll likely need to download the source from the GitHub repo and make the changes yourself.

    Looking at the _panOrMoveMainScroll method in src/js/gestures.js, it appears that the panning logic is only present for horizontal gestures _direction === 'h' && axis === 'x', whereas the mainScroll is present for vertical gestures.

    If you think this is useful enough to warrant the development effort, I'd recommend taking the latest branch and adding a default option in core.js that allows the directions to be toggled and issuing a pull request to the original repository. This way future users can benefit from your effort and simply set a property to switch the directions.