dimsemenov / Magnific-Popup

Light and responsive lightbox script with focus on performance.
http://dimsemenov.com/plugins/magnific-popup/
MIT License
11.38k stars 3.49k forks source link

Can not load ajax content and then use gallery with images in content #869

Open COLABORATI opened 8 years ago

COLABORATI commented 8 years ago

I tried several variations of this:

1.) Load ajax content from link 2.) inside that ajax content is a simple div with image links (can be modified) 3.) from that content received via ajax create a popup with gallery that navigates the contained imgs.

I tried everything, no success. How can I load a list of image links via ajax and then make a gallery of them? I tried several variations of gallery: true and I do not understand how delegate comes into play with this.

I can not understand from the docs how to do it - please, Dmitry, would you like to show an example of how to do this? Thanks!

MoacirFuhr commented 8 years ago

You just need to work with the method ajaxComplete. Like this, so you gonna call the lightbox function only after the ajax call has complete.

$(document).ajaxComplete(function(event,request,settings){      
    $('.fotos-links2 a').magnificPopup({type:'image'});
});
ZachBerman commented 7 years ago

Similar issues here, having trouble with a simple photo gallery through ajax. Anyone have an example?

infinity-webdesigns commented 6 years ago

I had a similar issue. I fixed it by placing the following in my javascript file (outside of the document ready function):

$(document).ajaxComplete(function(event,request,settings)
{
    $('[your gallery class here]').each(function() {
        $(this).magnificPopup({
            delegate: 'a',
            type: 'image',
            gallery:{enabled:true}
        });
    });
});

Hope this helps