2010-09-19 38 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>'); 
});