Close panel when clicking outside the box

Hey,

So I have several panels in my WebSite (box elements) wich appear when you click on the icon, as the image demonstrates bellow.


Basically when you click the icon the boxes appear, when you click it again the boxes disappears. But what I want to do is when the user clicks outside that box it closes. I thought of adding a box that covers the entire page, but this would apply to all pages and each page’s size is different.
Can someone please help me with this?

SOLVED! I found a pretty cool solution!
Check it out: https://www.wix.com/code/home/forum/community-discussion/solution-close-panel-when-clicking-outside-the-box