以下是流行的jquery 盖丽亚的主页。我需要插入下载链接到右下角的活动图像。现在有可用的统计数据,如(3/10),它表示列表中的当前数字。也许已经有人这么做了。最快的方法是什么?
gearsdigital's UPD:UPD:使用我编写的代码:
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函数不可用的错误。
发布于 2010-09-19 08:23:33
我将尝试从当前图像中获取当前Source属性,并将其作为链接追加。
//Untested. This is just a suggestion :)
currentImageSource = $('.galleria-image img').attr('src');
$('.galleria-counter').append('<a href="'+currentImageSource+'">Download</a>');但是像这样的链接会分开打开图像,而不是普通下载。如果你想要一个“真正的”下载,你必须把这个图像放在一个压缩存档。
$('.galleria-counter').append('<a href="'+currentImageSource+'.zip">Download</a>');这会产生类似的东西:http://www.example.com/galleria/img/mygreatimage.jpg.zip
为我工作:
<!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>发布于 2010-09-19 11:49:02
从imgHandle对象(而不是jquery对象)获取DOMEvent。
由于attr是jQuery对象的一部分,所以需要将dom对象传输到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>');
});https://stackoverflow.com/questions/3744963
复制相似问题