Magnific-Popup, Limit items to direct siblings

大城市里の小女人 提交于 2020-01-22 22:55:13

问题


How can I limit magnific-popup gallery to direct siblings? When I open an image from the first .child, I don’t want the images from the second .child to be in the gallery.

The html structure:

<div class="parent">
    <div class="child">
        <a class="image-link" href="img/red1.jpg"><img src="img/red1.jpg"></a>
        <a class="image-link" href="img/red2.jpg"><img src="img/red2.jpg"></a>
        <a class="image-link" href="img/red3.jpg"><img src="img/red3.jpg"></a>
        <a class="image-link" href="img/red4.jpg"><img src="img/red4.jpg"></a>
        <a class="image-link" href="img/red5.jpg"><img src="img/red5.jpg"></a>
    </div>

    <div class="child">
        <a class="image-link" href="img/city1.jpg"><img src="img/city1.jpg"></a>
        <a class="image-link" href="img/city2.jpg"><img src="img/city2.jpg"></a>
        <a class="image-link" href="img/city3.jpg"><img src="img/city3.jpg"></a>
        <a class="image-link" href="img/city4.jpg"><img src="img/city4.jpg"></a>
        <a class="image-link" href="img/city5.jpg"><img src="img/city5.jpg"></a>
    </div>
</div>

how I initialize Magnific-Popup:

$('.child').magnificPopup({ 
    delegate: '.image-link',
    type:'image', 
    gallery: {
        enabled: true
    }
});

回答1:


If delegate option is used, only like so:

$('.child').each(function() {
     $(this).magnificPopup({ 
        delegate: '.image-link',
        type:'image', 
        gallery: {
            enabled: true
        }
    });
});


来源:https://stackoverflow.com/questions/16603714/magnific-popup-limit-items-to-direct-siblings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!