2011-07-11 24 views
0

我想模仿他們設置他們的例子庫預覽的方式。他們在fancybox調用中將靜態圖像構建爲一個數組。我一直試圖用隱藏div $("#imgGallery").html()替換該數組,其中包含引號和所有內容。但無法讓fancybox出現。fancybox畫廊傳遞元素內容作爲數組

如何將$(「#imgGallery」)。html()內容作爲數組傳遞給$ .fancybox()調用。

$("#manual2").click(function() { 
     $.fancybox([ 
      'http://farm5.static.flickr.com/4044/4286199901_33844563eb.jpg', 
      'http://farm3.static.flickr.com/2687/4220681515_cc4f42d6b9.jpg', 
      { 
       'href' : 'http://farm5.static.flickr.com/4005/4213562882_851e92f326.jpg', 
       'title' : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' 
      } 
     ], { 
      'padding'   : 0, 
      'transitionIn'  : 'none', 
      'transitionOut'  : 'none', 
      'type'    : 'image', 
      'changeFade'  : 0 
     }); 
    }); 
+0

給你imgGallery div的例子。 – kwicher

回答

0

我設法用下面的代碼來做到這一點:

$.fancybox(
      [{ href: '/images/title1.png', title: 'title1'}, 
      { href: '/images/title2.png',title: 'title2'}], 
      { 
       'padding': 0, 
       'transitionIn': 'none', 
       'transitionOut': 'none', 
       'type': 'image', 
       'changeFade': 0, 
       'titlePosition': 'inside', 
       'titleFormat': formatTitle 
      }); 
    }); 

function formatTitle(title, currentArray, currentIndex, currentOpts) { 
    return '<div></span>' + (title && title.length ? '<b>' + title + '</b>' : '') + '<br/>image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</div>'; 
}