javascript - 我怎样才能得到一个华丽的弹出窗口来在一个动态画廊中同时显示图像和 iframe 视频?

标签 javascript jquery iframe plugins magnific-popup

我正在使用 magnific popup 通过以下方式创建图片库:

$('.main-content').magnificPopup({
  delegate: '.gallery', // child items selector, by clicking on it popup will open
  type: 'image',
  gallery: {enabled:true}
  // other options
});

我还有一个使用以下内容嵌入的视频:

$('.video').magnificPopup({
    type: 'iframe',
    iframe: {
      markup: '<div class="mfp-iframe-scaler">'+
                '<div class="mfp-close"></div>'+
                '<iframe class="mfp-iframe" frameborder="0" allowfullscreen></iframe>'+
              '</div>', // HTML markup of popup, `mfp-close` will be replaced by the close button

      patterns: {
        youtube: {
          index: 'youtube.com/', // String that detects type of video (in this case YouTube). Simply via url.indexOf(index).

          id: 'v=', // String that splits URL in a two parts, second part should be %id%
          // Or null - full URL will be returned
          // Or a function that should return %id%, for example:
          // id: function(url) { return 'parsed id'; } 

          src: '//www.youtube.com/embed/%id%?autoplay=1' // URL that will be set as a source for iframe. 
        },
        vimeo: {
          index: 'vimeo.com/',
          id: '/',
          src: '//player.vimeo.com/video/%id%?autoplay=1'
        },
        gmaps: {
          index: '//maps.google.',
          src: '%id%&output=embed'
        }

        // you may add here more sources

      },

      srcAction: 'iframe_src', // Templating object key. First part defines CSS selector, second attribute. "iframe_src" means: find "iframe" and set attribute "src".
    }

});

如何将视频 iframe 合并到图库中?我无法使用项目数组,因为我的图像和视频是动态的。

谢谢

最佳答案

这是我为此使用的一个简单解决方案:

$('.image-link, .video-link').magnificPopup({
    callbacks: {
      elementParse: function(item) {
         // the class name
         if(item.el.context.className == 'video-link') {
           item.type = 'iframe';
         } else {
           item.type = 'image';
         }
      }
    },
    gallery:{enabled:true},
    type: 'image',
});

它应该与类型格式化程序一起工作。

关于javascript - 我怎样才能得到一个华丽的弹出窗口来在一个动态画廊中同时显示图像和 iframe 视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22792184/

相关文章:

javascript - 仅刷新某些 iframe,而不使用 jQuery 刷新整个页面

javascript - Vanilla JavaScript + 多重选择 - 在多项选择中获得相同的值?

jquery 访问动态内容的元素

Jquery 和 Django 多复选框

php - 如何将多个 jQuery 日期选择器值发送到数据库

javascript - 使用 iframe 获取 Jira Scrum Board

javascript - 使用 onClick var 在 javascript 中更改 id?

javascript - 如何使用 Materialize.css 框架自动完成获得重叠

javascript - dojox.form.Rating 未出现在发布数据中

javascript - 如何在javascript中设置下载文件等待时的加载符号?