Search code examples
highslide

Close all Highslide on click outside


I have a Highslide plugin on my webpage with basic popups, what I need is that when a user clicks outside all the open popups should close.

Tried this but without luck:

   hs.close();

Solution

  • After doing some research in my console I came up with this solution and is working pretty fine..

    $(document).mouseup(function (e)
    {
        if($(".highslide-wrapper").length==0)
            return;
    
        var container = $(".highslide-wrapper");
    
        if (!container.is(e.target) 
            && container.has(e.target).length === 0) 
        {
            for (var i = 0; i < hs.expanders.length; i++) {
                var exp = hs.expanders[i];
                if (exp) exp.close();
            }
        }
    });
    

    And you can also have a check if the clicked element is another thumbnail or not..