2013-10-21 37 views
3

我有一個項目數組,看起來是這樣的:莊重,彈出打開某些項目

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> 

html內容對於每個「#white-popup」具有相同的結構。 現在,我打開magnifica-popup的方式是通過從引導程序傳送帶觸發.magnificPopup函數,其中我有與我的數組中相同數量的項目。我需要做些什麼來觸發我的js數組中的某個項目。例如,如果我點擊我的旋轉木馬上的第二個項目,我會讓.magnificPopup打開所有項目,但是從第二個項目開始。

在此先感謝。

回答

1

open方法似乎不再支持簡單地增加了指數可選的第二個參數。我想這是來自Magnific的舊版本,因爲它似乎沒有工作。

根據文檔,您現在可以在選項中包含索引參數。

這對我有效。

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