使用 Fancybox,当模式打开时,是否有地方可以显示组中图像的数量?例如“第 1 张图片(共 4 张)”、“第 2 张图片(共 4 张)”等?
最佳答案
如果您使用 fancybox v1.3.4,请使用 API 选项 titleFormat
,例如:
$(document).ready(function(){
$(".fancybox").fancybox({
'titlePosition': 'over',
'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' of ' + currentArray.length + ' ' + title + '</span>';
}
}); // fancybox
}); // ready
如果您使用 fancybox v2.0.6+,请使用 API 选项 beforeShow
,如下所示:
$(document).ready(function(){
$(".fancybox").fancybox({
helpers : {
title : { type : 'over' }
}, // helpers
beforeShow : function() {
this.title = (this.title ? '' + this.title + '' : '') + 'Image ' + (this.index + 1) + ' of ' + this.group.length;
} // beforeShow
}); // fancybox
}); // ready
对于 v2.0.6 之前的版本(仅限 v2.x),请使用 afterLoad
代替。检查 this link for more
关于jquery - Fancybox:显示组中图像的总数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11603753/