Magnific popup requires double-clicking to open image slider

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] // Will preload 0 - before current, and 1 after the current image
                }
            });
            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.

+4
2

.magnificPopup('open') .

:

$("#Fixed-Container").on("click", ".popup-gallery", function (event) {
    $('.popup-gallery').magnificPopup({
        delegate: 'a',
        type: 'image',
        gallery: {
            enabled: true,
            navigateByImgClick: true,
            preload: [0, 1] // Will preload 0 - before current, and 1 after the current image
        }
    }).magnificPopup('open');
    event.preventDefault();
});
+6

, , . .

    $('body').on('click', "a.videolink", function(e){
      $.magnificPopup.open({
        items: {
          src: $(this).attr('href')
        },
        type: 'iframe',
      });
      e.preventDefault();       
    });
0

Source: https://habr.com/ru/post/1533479/


All Articles