Javascript 在画廊内使用放大弹出窗口

Javascript 在画廊内使用放大弹出窗口,javascript,html,css,magnific-popup,Javascript,Html,Css,Magnific Popup,我试图在里面使用,但我遇到了麻烦。它似乎没有拾取我希望它处理的锚定标记,单击图像只会直接到达href位置 我知道它在页面上工作,因为如果我手工编写一些普通的标记,它工作得很好: <a class="gallery-image" href="http://localpath/imagelarge.jpg"> <img src="http://localpath/imagethumb.jpg"> </a> 但是,由于我使用的是Justified Ga

我试图在里面使用,但我遇到了麻烦。它似乎没有拾取我希望它处理的锚定标记,单击图像只会直接到达href位置

我知道它在页面上工作,因为如果我手工编写一些普通的标记,它工作得很好:

<a class="gallery-image" href="http://localpath/imagelarge.jpg">
    <img src="http://localpath/imagethumb.jpg">
</a>

但是,由于我使用的是Justified Gallery,因此生成的标记并不完全相同:

<div class="justifiedGallery" id="gallery">
    <div class="jg-row" style="height: 128px; margin-bottom: 1px;">
        <div class="jg-image" style="left: 0px;">
             <a class="gallery-image" href="http://localpath/imagelarge.jpg">
                 <img style="width: 192px; height: 128px; display: inline; opacity: 1;" alt="undefined" src="http://localpath/imagethumb.jpg">
             </a>
        </div>
    </div>
</div>

以下是我在工作示例和非工作示例中使用的JavaScript:

<script type="text/javascript">
    $(document).ready(function () {
        $("#gallery").justifiedGallery({
            'usedSuffix': 'lt240',
            'justifyLastRow': false,
            'rowHeight': 120,
            'fixedHeight': false,
            'captions': false,
            'margins': 1
        });

        $('.gallery-image').magnificPopup({
            type: 'image'
        });
    });
</script>

$(文档).ready(函数(){
美元(“#画廊”)。合理的画廊({
“usedSuffix”:“lt240”,
“justifyLastRow”:false,
“行高”:120,
“fixedHeight”:false,
“说明”:错误,
“边距”:1
});
$('.gallery image')。放大弹出窗口({
键入:“图像”
});
});
为了添加Gallery image类,我确实需要调整“对齐的Gallery”,但其他的都是库存

我觉得有些矛盾,但我似乎找不到


以前有人用过这两个吗?我初始化放大镜的方式有什么问题吗?

我以前没有使用正确的库插件,但正如我所见,您的标记是正确的。我敢打赌,在画廊初始化期间会有一种情况

Gallery插件可能会操纵DOM,因此我建议在Gallery完成初始化后绑定放大弹出窗口,您可以使用onComplete(对齐Gallery)回调。

您可以添加以下内容:

$("#gallery").justifiedGallery({
        'usedSuffix': 'lt240',
        'justifyLastRow': false,
        'rowHeight': 120,
        'fixedHeight': false,
        'captions': false,
        'margins': 1
    }).magnificPopup({type:'image', delegate: '.gallery-image'});

成功了。谢谢顺便说一句,放大镜是迄今为止我试过的最好的灯箱。