I have a scenario in which my code for displaying image thumbnails is loaded dynamically in the DOM. By clicking on the thumbnail, I want to download the full image using maginfic popup . The following is my opinion:
<div class="Right-Panel-Section popup-gallery">
<h2>Images</h2>
@foreach (var media in @Model.lsContentMedia)
{
<div class=" Float-Left" data-id="@media.MediaId">
<a href="@media.ContentMediaFileName" >
<img src="@media.ContentMediaFileName" style="width:80px;height:80px;margin:5px;" title="@media.Description" class="gallery-item"/>
</a>
</div>
}
</div>
Since I cannot directly access DOM elements, I use a delegate to connect Magnific, as shown below:
$("#Fixed-Container").on("click", ".popup-gallery", function (event) {
$('.popup-gallery').magnificPopup({
delegate: 'a',
type: 'image',
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0, 1]
}
});
event.preventDefault();
});
I correctly included both the style and the script. However, I can only view images after the first press twice on any image. I would expect it to work with one click, always. Any help on this would be greatly appreciated.