2012-03-10 116 views
0

我不知道如何可以創建與網址加載頁面的圖像的收藏夾鏈接 Fancybox - 如何從網址加載圖片?

這裏是我的代碼,但它不工作:

$("a.picture").click(function() { 
     $.fancybox({ 
      'padding'   : 0, 
      'overlayShow' : false, 
      'transitionIn' : 'elastic', 
      'transitionOut' : 'elastic', 
      'titlePosition' : 'over', 
      'type' : 'image', 
      'titleFormat' : function(title, currentArray, 
currentIndex, currentOpts) { 
      return '<span id="fancybox-title-over">' + (currentIndex + 
1) + '/' + currentArray.length + (title.length ? ' &nbsp; ' + 
title : '') + '</span>'; 
      } 
     }); 
     return false; 
    }); 

和HTML代碼

<a class="picture" href="http://localhost/test/my_page.html" title="Picture Page">Link</a>

謝謝!

+1

如果打開一個html頁面,你應該設置''type':'iframe'而不是'type':'image' – JFK 2012-03-11 10:35:01

回答

5

你有上面還腳本假設你有一個這樣的HTML:

<a class="picture" href="images/picture.jpg">open image</a> 

那麼你也應該添加到您的腳本選項href

$("a.picture").click(function() { 
     $.fancybox({ 
      'padding'   : 0, 
      'overlayShow' : false, 
      'href': this.href, //<--LIKE THIS 
      // etc.... 

該選項將提供fancybox將加載圖像的URL。

注意:提出問題是OK,我們很高興提供幫助,但作爲@ofir評論,你應該提供反饋,並接受他人提供這樣的人會覺得積極地幫助你在未來的正確答案。