【问题标题】:Magnific-Popup Gallery don't open twiceMagnific-Popup Gallery 不会打开两次
【发布时间】:2019-06-01 00:29:33
【问题描述】:

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

画廊打开一次,一切正常,但如果我关闭画廊,我无法打开两次,我有这个错误:

未捕获的类型错误:无法读取未定义的属性“顶部”

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');
            }
        }   
    });
});

【问题讨论】:

  • 删除缩放选项后一切正常。

标签: jquery gallery lightbox magnific-popup


【解决方案1】:

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

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多