我想知道如何在 Fancybox 2 的回调函数中获取当前图像名称/src。我发现 a post这给出了答案,但在 Fancybox 2 中不起作用。
示例:
$(document).ready(function() {
$(".fancybox_share")
.attr('rel', 'gallery')
.fancybox({
afterShow: function() {
// Download button
$('.fancybox-wrap').append('<div id="fancy_download"></div>')
.on("click", "#fancy_download", function(){
var src = $('#fancybox-img').attr('src'); // Solution proposed in another post -> didn't work
});
}
});
});
感谢您的帮助。
最佳答案
或者,如果您想知道当前链接(适用于任何内容类型),则只需使用 this.href
/$.fancybox.current.href
- http://jsfiddle.net/sGaAW/2/
$(".fancybox_share")
.attr('rel', 'gallery')
.fancybox({
afterShow: function () {
console.log( this.href );
// OR
console.log( $.fancybox.current.href );
}
});
关于jquery - 在 Fancybox 2 中获取当前图像名称/src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18241453/