2010-09-19 49 views
1

以下是流行的jquery插件galleria的主頁。我需要將下載鏈接插入到活動圖像的右下角。現在有像(3/10)這樣的可用統計量,它表示當前列表中的數字。 也許有人已經這樣做了。什麼是最快的方式?環球免稅店jquery插件


UPD:使用gearsdigital的想法,我寫的代碼:

var gallery = Galleria.get(0); 

gallery.bind(Galleria.IMAGE, function(e) { 
    imgHandle = e.imageTarget; 
    console.log(imgHandle); 
    console.log(imgHandle.attr('href')); 
    //$('.galleria-counter').append('<a href="'+imgHandle.attr('src')+'">Download</a>'); 
}); 

第一個日誌行顯示了類似:

<img width="584" height="438" src="http://....jpg" style="display: block; position: relative; left: 0px; top: -4px; opacity: 1;"> 

但如何獲得src的位置,我看到的錯誤,attr功能不可用BLE。

回答

1

我會嘗試從當前圖像中獲取當前源屬性並將其作爲鏈接追加。

//Untested. This is just a suggestion :) 
currentImageSource = $('.galleria-image img').attr('src'); 
$('.galleria-counter').append('<a href="'+currentImageSource+'">Download</a>'); 

但是,像這樣的鏈接將打開圖像分離,不會下載普通。如果你想要一個「真正的」下載,你必須把這個圖像放入一個zip檔案。從DOMEvent,而不是一個jQuery對象

<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     <title>Example</title> 
     <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> 

     <script type="text/javascript"> 
      $(document).ready(function() { 

       currentImageSource = $('.container img').attr('src'); 
       $('.placeholder').append('<a href="'+currentImageSource+'">Download</a>'); 

      }); 

     </script> 
    </head> 

    <body> 
     <div class="container"> 
      <h2>Get img src</h2> 
      <img src="http://www.duba.at/wp-content/uploads/2007/08/bild_0570000.jpg" witdh="200" height="220"/> 
     </div> 

     <div class="placeholder"> 
      <h2>Append Here</h2> 
     </div> 

    </body> 
</html> 
+0

請看更新。 – Ockonal 2010-09-19 08:54:27

2

你得到imgHandle

$('.galleria-counter').append('<a href="'+currentImageSource+'.zip">Download</a>'); 

這將產生類似的東西:http://www.example.com/galleria/img/mygreatimage.jpg.zip

爲我工作。

由於attr是您需要將dom對象轉移到jquery對象的jQuery對象的一部分。

gallery.bind(Galleria.IMAGE, function(e) { 
    imgHandle = $(e.imageTarget); //Wrap it here 

    alert(imghandle.attr('href')) 

    //$('.galleria-counter').append('<a href="'+imgHandle.attr('src')+'">Download</a>'); 
});