【问题标题】:How can I combine inline elements with images in magnific popup having a displayed gallery如何将内联元素与具有显示画廊的放大弹出窗口中的图像结合起来
【发布时间】:2013-07-31 19:43:30
【问题描述】:

我正在使用Magnific Popup

我可以让它与galleries一起工作。

$(document).ready(function() {
    $('.popup-gallery').magnificPopup({
        delegate: 'a',
        type: 'image',
        gallery: {
            enabled: true,
            navigateByImgClick: true,
        }
    });
});

我实际上也可以混合内联元素with images,这基本上是我想要的:

$('#open-popup').magnificPopup({
    items: [
      {
        src: 'http://upload.wikimedia.org/wikipedia/commons/thumb/6/64/Peter_%26_Paul_fortress_in_SPB_03.jpg/800px-Peter_%26_Paul_fortress_in_SPB_03.jpg',
        title: 'Peter & Paul fortress in SPB'
      },
      {
        src: 'http://vimeo.com/123123',
        type: 'iframe' // this overrides default type
      },
      {
        src: $('<div class="white-popup">Dynamically created element</div>'), // Dynamically created element
        type: 'inline'
      },
      {
        src: '<div class="white-popup">Popup from HTML string</div>', // HTML string
        type: 'inline'
      },
      {
        src: '#my-popup', // CSS selector of an element on page that should be used as a popup
        type: 'inline'
      }
    ],
    gallery: {
      enabled: true
    },
    type: 'image' // this is a default type
});

我的问题是,在混合示例中,我没有显示缩略图“画廊”,我基本上想要的是缩略图,当点击它时表现得像画廊,但中间有一个内联元素。

内联元素将有一个缩略图(和实际图像),但单击时将是一个内联元素。

我可以使用fancybox 完成此操作,如果您单击缩略图,您可以看到here,这可能有助于澄清我的需求。 (由于缺乏移动设备的移动支持,我正在尝试使用 Magnific 弹出窗口来实现相同的目标)。

【问题讨论】:

    标签: javascript jquery gallery magnific-popup


    【解决方案1】:

    您可以将mfp-TYPE CSS 类添加到应该具有非默认内容类型的缩略图元素。 http://dimsemenov.com/plugins/magnific-popup/documentation.html#content_types

    【讨论】:

    • 非常感谢,抱歉延迟回答我在假期:) 这非常有效!感谢您的帮助,顺便说一句,插件很棒!
    【解决方案2】:
    jQuery(document).ready(function($) {
        $('.owl-wrapper').magnificPopup({
                delegate: 'a',
                type: 'image',
                tLoading: 'Loading image #%curr%...',
                mainClass: 'mfp-img-mobile',
                gallery: {
                    enabled: true,
                    navigateByImgClick: true,
                    preload: [0,1]
                },
                image: {
                    tError: '<a href="%url%">The image #%curr%</a> could not be loaded.',
                },
                callbacks: {
                    elementParse: function(item) {
             if(item.el.context.className == 'video-link') {
                 item.type = 'iframe';
             } else if(item.el.context.className == 'inline-link') {
                item.type = 'inline';
             } else {
                 item.type = 'image';
             }
                    }
                },
        });
    });
    

    【讨论】:

    • 感谢您提供此代码 sn-p,它可能会提供一些有限的即时帮助。 proper explanation 将通过展示为什么这是解决问题的好方法,并使其对有其他类似问题的未来读者更有用,从而大大提高其长期价值。请edit您的回答添加一些解释,包括您所做的假设。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-24
    • 2017-08-13
    相关资源
    最近更新 更多