PhotoSwipe icon indicating copy to clipboard operation
PhotoSwipe copied to clipboard

bgClickAction not working on mobile

Open VioletFlare opened this issue 7 months ago • 1 comments

Hi, I have this code:

    const closeGallery = (pt, evt) => {
        if (evt.target.classList.contains('pswp__img')) {
            pswp.next();
        } else {
            pswp.close();
        }
    }
lightbox = new PhotoSwipeLightbox({
            dataSource,
            pswpModule: () => import("photoswipe"),
            doubleTapAction: "zoom",
            bgClickAction: (pt, evt) => closeGallery(pt, evt),
});

It seems like bgClickAction isn't triggering on mobile, while debugging the breakpoint is not hit.

PS version: 5.4.4

VioletFlare avatar May 30 '25 13:05 VioletFlare

I missed the part where it says in the docs that it only captures mouse clicks. Is there an action for tap? :)

VioletFlare avatar May 30 '25 13:05 VioletFlare

find a solution?

aehlke avatar Jul 09 '25 18:07 aehlke

Yep, in my case I close the gallery on bg click.

        lightbox.pswp.on("pointerUp", (ev) => {
            const isBgClick = [...ev.originalEvent?.target?.classList].includes("pswp__item");

            if (isBgClick) {
                lightbox.pswp.close();
            }
       })

VioletFlare avatar Jul 13 '25 23:07 VioletFlare