# How to close the lightbox

**URL:** <https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447>\
**Category:** Ask the community\
**Tags:** wix-forum, question, code\
**Created:** [April 3, 2018, 4:07pm UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447 "2018-04-03T16:07:19Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![keawe-wong](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/keawe-wong/32/1943_2.png) [@keawe-wong](https://forum.wixstudio.com/u/keawe-wong)\
**Post date:** [April 3, 2018, 4:07pm UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/1 "2018-04-03T16:07:19Z")

</div>

Here is the quick tip I would like to share (not a question).

I had a couple people emailed me personally from the Wix forum asking this question. I thought I post it here in case people are searching for the answer.

I understand the Lightbox API maybe a bit hard to find. It is in the wix-window API. Here you have it:

> **[Lightbox - Velo API Reference - Wix.com](https://www.wix.com/velo/reference/wix-window-frontend/lightbox)**
>
> A lightbox pops up on your site to grab your visitor's attention.

And to close the lightbox, use this:  
wixWindow.lightbox.close();

Hope that helps.

---

<div class="post-metadata">

**Author:** ![rouka1](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rouka1](https://forum.wixstudio.com/u/rouka1)\
**Post date:** [April 25, 2018, 2:44pm UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/2 "2018-04-25T14:44:44Z")

</div>

Hi Keawe,  
I am trying to close the light box when I move away from the button , currently I have  
On the site tab I have the following codes :

$w.onReady(function () {  
//TODO: write your page related code here…

});

import window from ‘wix-window’;

export function button2\_onmouseIn(event) {  
window.openLightbox(‘brands’);  
}

export function button3\_onmouseIn(event) {  
window.openLightbox(‘perfumes’);  
}

and on the page tab I have the following codes :

});

import window from ‘wix-windows’;

export function button3\_onmouseIn(event) {  
window.openLightbox(‘perfumes’);  
}

export function lightbox2\_onmouseOut(event) {  
window.lightbox.close();

}

---

<div class="post-metadata">

**Author:** ![keawe-wong](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/keawe-wong/32/1943_2.png) [@keawe-wong](https://forum.wixstudio.com/u/keawe-wong)\
**Post date:** [April 25, 2018, 6:20pm UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/3 "2018-04-25T18:20:19Z")

</div>

**Hey rouka1,** Does it work?

---

<div class="post-metadata">

**Author:** ![rouka1](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rouka1](https://forum.wixstudio.com/u/rouka1)\
**Post date:** [April 26, 2018, 7:43am UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/4 "2018-04-26T07:43:58Z")

</div>

Hi Keawe,  
Thanks for your reply and please accept my apology for late reply due to time zone difference,  
I have now replaced my lightbox with a content box and used show & hide codes to make the content box show when mouse is on button and hide when mouse is away from button but I need to give site visitors “time” when they are on the lightbox to select an item from within the lightbox, is it possible ? and what is the code ?

---

<div class="post-metadata">

**Author:** ![rouka1](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rouka1](https://forum.wixstudio.com/u/rouka1)\
**Post date:** [April 26, 2018, 8:07am UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/5 "2018-04-26T08:07:52Z")

</div>

My website : [https://www.perfumes-bouquet.com/](https://www.perfumes-bouquet.com/)

---

<div class="post-metadata">

**Author:** ![keawe-wong](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/keawe-wong/32/1943_2.png) [@keawe-wong](https://forum.wixstudio.com/u/keawe-wong)\
**Post date:** [April 26, 2018, 8:21am UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/6 "2018-04-26T08:21:15Z")

</div>

I think this approach may work. Here is the pseudo code follows by the simple code.

Pseudo:  
On top of the code page, create a variable (call it myTimer) to hold a setTimeOut pointer.  
In your onMouseOut handler, Use setTimeout to delay the content box to disappear in x second.  
That will give your user enough time to go inside before the content box (you still call it lightbox) disappear.  
Clear the timer using the variable myTimer when the user selects an item. That way the user can spend all the time they want to make selection decision.  
When the user’s mouse is out of the content box, reset the timer to make it disappear.

Here is the simple code (I tested it. It works)

let myTimer;  
$w.onReady(function () {  
// write some code here  
});

export function button\_mouseIn() {  
clearTimeout(myTimer);   
$w(‘#container’).show();  
}

export function button\_mouseOut() {  
myTimer = setTimeout(()=\>{  
$w(‘#container’).hide();  
},1500);  
}

export function container\_mouseIn() {  
clearTimeout(myTimer);  
}

export function container\_mouseOut() {  
myTimer = setTimeout(()=\>{  
$w(‘#container’).hide();  
},1500);  
}

Note:  
– Make sure the myTimer is on top of your page. Because it needs to be accessed by all the handlers.  
– The 1500 is just my test. You can use whatever wait time you want.

Hope that works for you 🙂

P.S. I am not part of Wix support team. I am just some random guy who like to pitch in to help the Wix Code community. I will try to get back to you whenever I have spare time. But I can’t promise I will reply in time.

Happy coding.

---

<div class="post-metadata">

**Author:** ![keawe-wong](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/keawe-wong/32/1943_2.png) [@keawe-wong](https://forum.wixstudio.com/u/keawe-wong)\
**Post date:** [April 26, 2018, 8:25am UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/7 "2018-04-26T08:25:38Z")

</div>

Also, you have "import window from ‘wix-windows’; " on top of each export function…  
Hope you are really not doing that. You should only import something on top of the page once only.  
Just thought I mention it. Maybe you already know. 🙂

---

<div class="post-metadata">

**Author:** ![rouka1](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rouka1](https://forum.wixstudio.com/u/rouka1)\
**Post date:** [April 26, 2018, 9:12am UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/8 "2018-04-26T09:12:51Z")

</div>

Thanks a lot for your generous reply, I will implement it on my site and come back to you with a million thanks

---

<div class="post-metadata">

**Author:** ![rouka1](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rouka1](https://forum.wixstudio.com/u/rouka1)\
**Post date:** [April 26, 2018, 6:47pm UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/9 "2018-04-26T18:47:59Z")

</div>

Hi Keawe,  
I placed the code but when the mouse is inside the container the setTimeout delay doesn’t work :  
export function container\_mouseIn() {  
clearTimeout(myTimer);  
}

export function container\_mouseOut() {  
myTimer = setTimeout(()=\>{  
$w(‘#container’).hide();  
},1500);  
}

and to show you the code I placed in full is as follows :  
let myTimer;  
$w.onReady(function () {  
// write some code here  
});

export function button18\_onmouseIn() {  
clearTimeout(myTimer);   
$w(“#box3”).show();  
}

export function button18\_onmouseOut() {  
myTimer = setTimeout(()=\>{  
$w(“#box3”).hide();  
},1500);  
}

export function box3\_onmouseIn() {  
clearTimeout(myTimer);  
}

export function box3\_onmouseOut() {  
myTimer = setTimeout(()=\>{  
$w(“#box3”).hide();  
},1500);  
}

Kindly advise what did I misplaced ?

Thanks & Best Regards

---

<div class="post-metadata">

**Author:** ![keawe-wong](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/keawe-wong/32/1943_2.png) [@keawe-wong](https://forum.wixstudio.com/u/keawe-wong)\
**Post date:** [April 26, 2018, 7:48pm UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/10 "2018-04-26T19:48:33Z")

</div>

Did you check to make sure all the handlers are named correctly for each element? For example: Do you have the function names correct correctly for the box3 onmouseIn?  
I will screen record what I have done and post it here to show you after on today.

---

<div class="post-metadata">

**Author:** ![rouka1](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rouka1](https://forum.wixstudio.com/u/rouka1)\
**Post date:** [April 26, 2018, 7:54pm UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/11 "2018-04-26T19:54:40Z")

</div>

Thanks for your reply, do you think that those codes are not copied correctly by me ?

export function box3\_onmouseIn() {  
clearTimeout(myTimer);  
}

export function box3\_onmouseOut() {  
myTimer = setTimeout(()=\>{  
$w(“#box3”).hide();  
},1500);  
}

Thanks for your reply and screen record if possible would be great

---

<div class="post-metadata">

**Author:** ![keawe-wong](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/keawe-wong/32/1943_2.png) [@keawe-wong](https://forum.wixstudio.com/u/keawe-wong)\
**Post date:** [April 27, 2018, 12:45am UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/12 "2018-04-27T00:45:28Z")

</div>

Really hard to tell without actually look at your page in the editor.  
Here is the video of my sample. Follow this and it should work.

[https://vimeo.com/266792566](https://vimeo.com/266792566)

---

<div class="post-metadata">

**Author:** ![rouka1](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rouka1](https://forum.wixstudio.com/u/rouka1)\
**Post date:** [April 27, 2018, 9:16am UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/13 "2018-04-27T09:16:11Z")

</div>

Thanks for your reply, should I remove any other codes from the page ? if no then where should I place your code (on the top of the page or on the bottom of the page ?

and what does the sentence "write some code here " mean ?

---

<div class="post-metadata">

**Author:** ![rouka1](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rouka1](https://forum.wixstudio.com/u/rouka1)\
**Post date:** [April 27, 2018, 12:55pm UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/14 "2018-04-27T12:55:49Z")

</div>

Hi Keawe,  
Please find attached the video showing the website page (button and content box) , codes added and result happening, kindly advise what might be wrong  
Thanks

[![](https://us1.discourse-cdn.com/wix/original/3X/2/5/25734551b57df418c373d07d1ab7886f2537e7a1.jpeg "Code Video") ](https://vimeo.com/266864252)

---

<div class="post-metadata">

**Author:** ![keawe-wong](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/keawe-wong/32/1943_2.png) [@keawe-wong](https://forum.wixstudio.com/u/keawe-wong)\
**Post date:** [April 27, 2018, 7:41pm UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/15 "2018-04-27T19:41:02Z")

</div>

Here this the problem I found. See the image here. Your box3 onMouseIn and onMouseOut handlers are empty. That’s why they don’t work! You need to put the correct function names in there. Just like you did for the buttons.

 ![](https://us1.discourse-cdn.com/wix/original/3X/b/a/ba647dfbdccb827b1aae96bdc162095ce5b33e75.png)  
Also, remove the code in the red box. It is not necessary. You were running the onReady function twice. It may create error in the future.

 ![](https://us1.discourse-cdn.com/wix/original/3X/2/0/20f1cef6b0092630ebfcc15837cd85b623f9d662.png)  
Hope that helps.

Have fun 🙂

Keawe

---

<div class="post-metadata">

**Author:** ![rouka1](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rouka1](https://forum.wixstudio.com/u/rouka1)\
**Post date:** [April 28, 2018, 2:45pm UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/16 "2018-04-28T14:45:59Z")

</div>

It worked perfectly, thank you very much for your valuable assistance  
Best wishes of a great weekend

---

<div class="post-metadata">

**Author:** ![rouka1](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rouka1](https://forum.wixstudio.com/u/rouka1)\
**Post date:** [May 5, 2018, 2:00pm UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/17 "2018-05-05T14:00:11Z")

</div>

Hi Keawe,  
Thank you very much for your assistance on the light box, I am trying to create a 3 category product search filter of the following :

1. Perfume Type : “For Him” or “For Her” or “Unisex”
2. By Brand
3. By price range : 50-100 & 100-200 & 200-250 & 250-300 & more than 300

In a manner like the search on the left side of this site : [Womens Perfume & Fragrances | LOOKFANTASTIC UK](https://www.lookfantastic.com/health-beauty/fragrance/female.list)

Is it possible for this product search filter to search for products in my Ecwid store attached to my Wix website ?

Best Regards

Ahmed

---

<div class="post-metadata">

**Author:** ![keawe-wong](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/keawe-wong/32/1943_2.png) [@keawe-wong](https://forum.wixstudio.com/u/keawe-wong)\
**Post date:** [May 17, 2018, 2:40pm UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/18 "2018-05-17T14:40:37Z")

</div>

Hi Ahmed, I haven’t used Ecwid store. I will find sometime to test it.  
Thanks,

Kw

---

<div class="post-metadata">

**Author:** ![uzair7438](https://avatars.discourse-cdn.com/v4/letter/u/77aa72/32.png) [@uzair7438](https://forum.wixstudio.com/u/uzair7438)\
**Post date:** [May 28, 2018, 12:13am UTC](https://forum.wixstudio.com/t/how-to-close-the-lightbox/41447/19 "2018-05-28T00:13:14Z")

</div>

Hello Sir,

I have added lightbox on this page [https://www.wellsquarednutrition.com/wellsquared-weekend](https://www.wellsquarednutrition.com/wellsquared-weekend)  
I wants to remove the lightbox after user enter their email and click on subscribe button.

I have also added this code in my footer but it’s till not working.
