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

Open image without link #650

Open tevart opened 9 years ago

tevart commented 9 years ago

Hi!

Is it possible to load image without a tag, by just adding class directly to image like <img class="image-popup" ..../>.

So i wan't to open image that has class image-popup, but doesn't have a tag.

tnx

MartinMuzatko commented 8 years ago

would also like to know

mtsknn commented 8 years ago
<img src="path/to/myimage.png" data-mfp-src="path/to/myimage.png" class="popup-img">
$('.popup-img').magnificPopup({
  type: 'image'
});

Like this? No need for the <a> tag. The image's src and data-mfp-src attributes don't need to be equal (so for example you can have src="thumbnail.png" and data-mfp-src="biggerimage.png").

MartinMuzatko commented 8 years ago

Thank you! I would have avoided this setup if it was documented properly:

        var images = $('.content.article article > div img')
        images.each(
            (index, item)=>
            {
                $(item).wrap(`<a class="magnific-popup" href="${item.src}"></a>`)
            }
        )
        $('.magnific-popup').magnificPopup({
          type: 'image'
        })