我正在尝试为您当前在 Fancybox 中查看的图像制作一个下载按钮。
我认为这将是一件容易的事情,因为 url 已经存储在 <img>
中标签,所以我想我可以将其重新用于链接。
我什至试图找到 <img>
的src
在 fancybox 中,然后 .append
到href
链接(<a>
标签)。我只是缺乏完成它的 jQuery 技能。
致fancybox.js
我添加了<a>
标签:
<img class="fancybox-image" src="image.jpeg" alt="" />
<a href="" class="test">Download</a>
我尝试复制并粘贴 image.jpeg
就像这样,但没有用:
var href = $('.fancybox-image').attr('href');
$('a.test').attr('href', href );
最佳答案
我不确定我是否理解你的问题,但你可以在 fancyBox 的标题区域内添加下载链接 - http://jsfiddle.net/zAe6Z/
$(".fancybox").fancybox({
afterLoad: function() {
this.title = '<a href="' + this.href + '">Download</a> ' + this.title;
},
helpers : {
title: {
type: 'inside'
}
}
});
关于jquery - Fancybox 下载图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18273091/