Close Lightbox on Scroll

Hi all,

So I am using the Wix Studio Lightbox element. I am hoping that there might be an option to close an open Lightbox when the user scrolls?

TIA

Hi, @Lee_Wilson !!

It’s probably difficult to achieve this using Wix’s default features. However, if you can code, it might not be impossible.

Currently, detecting scroll events accurately using Wix’s built-in functionality is quite challenging. While methods like onViewPortEnter() could potentially work, they should be considered a last resort.

One possible solution is to create a custom element that listens for scroll events and sends a message to the page code when triggered. At that point, you can store a property like "scrolled" along with the UTC timestamp in wix-storage.

As for closing the currently open lightbox, Wix provides a close() API, but I believe it can only be executed from within the lightbox itself (though I might be mistaken).

A possible workaround is to set up a simple loop inside the lightbox using setInterval, checking wix-storage every 100ms. By comparing the stored UTC timestamp with the current time, if the difference is below a certain threshold, you can determine that a scroll event has occurred and automatically close the lightbox using close().

That said, I feel there might be a simpler way to achieve this. :upside_down_face: