壮观的弹出画廊不会打开两次

时间:2019-01-05 20:05:53

标签: jquery gallery lightbox magnific-popup

我想从缩略图列表中打开一个宏伟的弹出式画廊。

画廊一次打开,一切正常,但是如果我关闭画廊,我将无法打开两次,并且出现此错误:

未捕获的TypeError:无法读取未定义的属性“ top”

magnific-popup.js中此行的错误报告: offset.top-=($(window).scrollTop()-paddingTop);

<div id="filelist">
    <div id="156" class="entreprise_img" style="background: url('5c30ff09d7566.jpg') no-repeat center;-moz-background-size: cover;-webkit-background-size: cover;background-size: cover;">
        <a href="#" class="entreprise_photo_btn_delete" title="Supprimer">Supprimer</a>
        <a href="5c30ff09d7566.jpg" class="magnific-gallery" style="position: absolute; bottom: 0;">VOIR</a>
    </div>
    <div id="157" class="entreprise_img" style="background: url('5c3104cab1fb7.jpg') no-repeat center;-moz-background-size: cover;-webkit-background-size: cover;background-size: cover;">
        <a href="#" class="entreprise_photo_btn_delete" title="Supprimer">Supprimer</a>
        <a href="5c3104cab1fb7.jpg" class="magnific-gallery" style="position: absolute; bottom: 0;">VOIR</a>
    </div>
</div>


$('#filelist').each(function(){
    $(this).magnificPopup({
        delegate: '.magnific-gallery',
        type: 'image',
        closeOnContentClick: false,
        closeBtnInside: false,
        mainClass: 'mfp-with-zoom mfp-img-mobile',
        image: {
            verticalFit: true
        },
        gallery: {
            enabled: true
        },
        zoom: {
            enabled: true,
            duration: 300, // don't foget to change the duration also in CSS
            opener: function(element) {
                return element.find('img');
            }
        }   
    });
});

1 个答案:

答案 0 :(得分:0)

我也有类似的错误。解决方法很简单:你需要重写zoom属性中的opener方法,以便它检查被打开的对象是否是一个图像。

zoom: {
        enabled: true,
        duration: 300,
        opener: function (element) {
                return element.is('img') ? element : element.find('img');
        }
    }