【问题标题】:magnific-popup open certain item in item arraymagnific-popup 打开项目数组中的某些项目
【发布时间】:2013-10-21 07:32:16
【问题描述】:

我有一个看起来像这样的项目数组:

items: [
{
    src: '#white-popup0',
    type: 'inline'
},
{
    src: '#white-popup1',
    type: 'inline'
},
{
    src: '#white-popup2',
    type: 'inline'
}]

还有一些与该数组匹配的 html 内容,看起来有点像这样:

<div id="white-popup0" class="white-popup">
<div class="popup_social_buttons">
    <iframe src="//www.facebook.com/plugins/like.php"><!-- FB like button --></iframe>
    <a href="//www.pinterest.com/pin/create/button/"><!-- Pinterest button --></a>
    <div id="___plusone_3" ><!-- G+ button --></div>
</div>
<img alt="alt text here" src="some_picture.jpg" class="img-responsive">
<button title="Close (Esc)" type="button" class="mfp-close">×</button>
</div>

每个“#white-popup”的 html 内容具有相同的结构。 现在,我打开 magnific-popup 的方式是从引导轮播中触发 .magnificPopup 函数,其中我的数组中的项目数量完全相同。我需要做一些事情来触发我的 js 数组中的某个项目。例如,如果我单击轮播中的第二个项目,我将让 .magnificPopup 打开所有项目,但从第二个项目开始。

提前致谢。

【问题讨论】:

    标签: jquery magnific-popup


    【解决方案1】:

    open 方法有一个可选的第二个参数,即要打开的项目的索引。

    $.magnificPopup.open({
     items: [
    {
        src: '#white-popup0',
        type: 'inline'
    },
    {
        src: '#white-popup1',
        type: 'inline'
    },
    {
        src: '#white-popup2',
        type: 'inline'
    }]
    
    }, 2);
    

    http://dimsemenov.com/plugins/magnific-popup/documentation.html#public_methods

    【讨论】:

    • 这正是我想要的,非常感谢。
    【解决方案2】:

    open 方法似乎不再支持简单地为索引添加可选的第二个参数。我猜这是来自旧版本的 Magnific,因为它似乎无法正常工作。

    根据文档,您现在可以在选项中包含索引参数。

    这对我有用。

    $.magnificPopup.open({
     items: [
    {
        src: '#white-popup0',
        type: 'inline'
    },
    {
        src: '#white-popup1',
        type: 'inline'
    },
    {
        src: '#white-popup2',
        type: 'inline'
    }],
     index: 2
    });

    【讨论】:

      猜你喜欢
      • 2023-03-02
      • 2015-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多