electerious / basicLightbox

The lightest lightbox ever made.
https://basiclightbox.electerious.com
MIT License
564 stars 55 forks source link

Closing when defined in a function #32

Closed adam-jones-net closed 4 years ago

adam-jones-net commented 4 years ago

Having a really simple problem. I'm trying to generate via a function and find that the close command doesn't work.

So I define global variable, then within the function try to update it whenever called.

var popup="";
function testPopup(content){
    popup=basicLightbox.create(content+` - <span class="btnClose">CLOSE</span>`).show();
}

Then to catch the close button click...


$(document).ready(function() {
     $(document).on('click','.btnClose', function(event){
        popup.close();
    });
});

When I click the close button I get popup.close is not a function msgs.
electerious commented 4 years ago

The show function isn't returning an instance. You can do it like this:

var popup="";
function testPopup(content){
    popup=basicLightbox.create(content+` - <span class="btnClose">CLOSE</span>`);
    popup.show();
}

Hope that helps :)

adam-jones-net commented 4 years ago

Ah damm i thought it was something simple thanks! ;)