0

我正在使用 magnific Popup 插件(http://dimsemenov.com/plugins/magnific-popup/documentation.html#initializing_popup

我可以先把我的代码放在这里:

 $(document).ready(function() {

$('.open-popup-link').magnificPopup({        
    // Delay in milliseconds before popup is removed
    removalDelay: 600,

    // Class that is added to popup wrapper and background
    // make it unique to apply your CSS animations just to this exact popup
    mainClass: 'mfp-fade',

    type:'inline',
    midClick: true, // Allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source in href.,
    callbacks: {
        beforeOpen: function() {
            if($(".image-container img").attr("title") != "" && $('.image-container img').length > 0){

                if ($('.imagetitle').length > 0) { 
                    // it exists 
                }else{
                    $(".image-container").append("<span class='imagetitle'>"+$(".image-container img").attr("title")+"</span>");
                    $(".image-container span.imagetitle").css({
                        "left": $(".image-container img").position().left+"px",
                        "margin-top":10+"px",
                        "margin-bottom":10+"px"                                
                    });
                }
            }
            //Make it a Gallery! - Whoop Whoop
            if($("div.white-popup").length > 1){
                $("div.white-popup").append("<div class='popupgalleryarrowleft'>&nbsp;</div>");
                $("div.white-popup").append("<div class='popupgalleryarrowright'>&nbsp;</div>");
            }
        },
        open: function(){
            // Klick Function für die Gallery einbauen!  
            $(".popupgalleryarrowleft").click(function(){
                $.magnificPopup.instance.prev();                    
            });

            $(".popupgalleryarrowright").click(function(){
                $.magnificPopup.instance.next();
            });
        }
    }                
});         

});

所以我想有一个内联画廊。它一切正常,但这部分没有:

 // Klick Function für die Gallery einbauen!  
            $(".popupgalleryarrowleft").click(function(){
                $.magnificPopup.instance.prev();                    
            });

            $(".popupgalleryarrowright").click(function(){
                $.magnificPopup.instance.next();
            });

我只是想得到下一个实例,当有一个时。当我在运行时通过 firebug 运行此代码时,它可以工作!

谁能帮我这个?希望。

问候大卫

4

2 回答 2

1

正在寻找同样的东西。我想你在找什么http://codepen.io/anon/pen/kInjm

$('.open-gallery-link').click(function() {

  var items = [];
  $( $(this).attr('href') ).find('.slide').each(function() {
    items.push( {
      src: $(this) 
    } );
  });

  $.magnificPopup.open({
    items:items,
    gallery: {
      enabled: true 
    }
  });
});
于 2014-09-04T10:08:51.133 回答
0

我需要为画廊创建自定义导航,所以我使用$.magnificPopup.instance.next();. 当放入画廊的点击处理程序时,它确实有效。否则,就找不到“下一个实例”,因为它还不存在。

单击底部/标题栏时,这将导航到下一个图库图像(在 codepen 上查看):

$('.gallery').magnificPopup({
  type: 'image', 
  gallery: {
    enabled: true
  }
});

$('.gallery').click(function() {
  $('.mfp-bottom-bar').click(function() {
    $.magnificPopup.instance.next();
  });
  return false;
});

这里有一个关于 Codepen 的更完整的例子,有多个画廊。

这个还使用回调调整弹出窗口中自定义导航和填充的高度。很有用,因为我项目中的导航按钮有很大的高度并且被屏幕底部截断。(默认情况下,仅使用图像高度本身来计算弹出窗口如何适合视口。)

希望这对某人有用。我知道这个问题是两年前的问题,但也许其他人也会像我一样通过谷歌搜索找到它。

于 2016-03-20T01:32:18.293 回答