set Timeout for Lightbox

Is there a way to set Timeout for a lightbox?

Thanks!

Hey,

You can do it using lightbox settings using delay slider if you want to do it as page opens.

Or if you want to add it via code you can use wix-window API and native JavaScript setTimeout, for example if you want to open lightbox whenever user clicks button:

const button = $w('#button1')
button.onClick(() => {
	setTimeout(() => {
		wixWindow.openLightbox("Welcome"); // use your lightbox name here			
	}, 1000)
})
2 Likes

Hello Maksim,

Thank you for your reply! I am wanting the lightbox to open automatically but then set Timeout to close it. Is this possible?

Thanks!

You can try using something like this inside your lightbox code

import wixWindow from 'wix-window';

$w.onReady(function () {
	setTimeout(wixWindow.lightbox.close, 2000)
});

But you’ll probably have to adjust timeout value to account for lightbox open animation,
Check out wixWindow API reference for what you can do with lightboxes in code

2 Likes

Thank you! I appreciate your help!

One last question:) Can we close with “FadeOut” ?

Yes, you can set the animation of the lightbox in the editor. The open and close animation is the same.