Magnific Popup - 索引错误

时间:2015-12-18 15:23:25

标签: javascript jquery magnific-popup

我不能让我的Magnific Popup使用索引选项。我的目标是在点击图像的索引上打开图库。在我的HTML中,每个图像都有这个:

<div class="open_gallery_index" data-id=5><img ... ></div>

然后我的JS看起来像这样:

$(function(){
  $('.open_gallery_index').click(function(){
    var i = Number($(this).data("id"));
    $.magnificPopup.open({
      items: g_items,
      gallery: {
        enabled: true
      },
      type: 'image'
    },i);
  });
})

但是点击图片时出现错误

  

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

虽然如果我手动设置变量i让我们说5,一切正常,所以问题必须在这个

var i = Number($(this).data("id"));

但我已经尝试了一切但没有成功,谢谢你的帮助。

3 个答案:

答案 0 :(得分:0)

像这样更新您的increment(7)属性。

data-id

答案 1 :(得分:0)

我认为$.magnificPopup.open需要src属性。不确定代码中的g_items是什么,但尝试这样的事情:

$.magnificPopup.open({
  items: {
    src: '.open_gallery_index',
    type: 'image'
  }
  gallery: {
    enabled: true
  },
},i);

答案 2 :(得分:0)

$.magnificPopup.open({
  items: g_items,
  gallery: {
    enabled: true
  },
  type: 'image'
},i);
i--;
i++;

它以这种方式与我合作,我不知道为什么