【发布时间】:2013-05-22 15:42:06
【问题描述】:
我有一个页面使用 fancybox 2.1.4 根据各自的rel 属性显示多个不同的图片库。
我一直在努力获取当前图片标题中显示的每个画廊的图片数量。通过this Stack Overflow post复制JFK描述的方法后,剩下的脚本就被禁用了。
我的代码如下。有人可以帮忙吗?
<script type="text/javascript">
$(document).ready(function() {
$(".fancybox").fancybox({
helpers : {
title: {
type: 'outside'
}
}, // helpers
afterLoad : function() {
this.title = (this.title ? " + this.title + '<br />' : ") + 'Image ' + (this.index + 1) + ' of ' + this.group.length;
}
});
//start fade transition
(function ($, F) {
F.transitions.resizeIn = function() {
var previous = F.previous,
current = F.current,
startPos = previous.wrap.stop(true).position(),
endPos = $.extend({opacity : 1}, current.pos);
startPos.width = previous.wrap.width();
startPos.height = previous.wrap.height();
previous.wrap.stop(true).trigger('onReset').remove();
delete endPos.position;
current.inner.hide();
current.wrap.css(startPos).animate(endPos, {
duration : current.nextSpeed,
easing : current.nextEasing,
step : F.transitions.step,
complete : function() {
F._afterZoomIn();
current.inner.fadeIn();//this rule controls the fadein of the next image
}
});
};
}(jQuery, jQuery.fancybox));
$(".fancybox")
/*.attr('rel', 'gallery')// am commenting this out so each gallery only loops through itself versus into the next gallery*/
.fancybox({
nextMethod : 'resizeIn',
nextSpeed : 200,//this rule controls the white flash action that happens just after an image is advanced
prevMethod : false,
helpers : {
title : {
type : 'outside'
}
}
}); //end fade transition
});
</script>
【问题讨论】:
-
这是一个小提琴:jsfiddle.net/bzelip/HGxHg
-
您将选择器
.fancybox绑定到fancybox 两次,因此第二个会覆盖第一个。此外,对于 v2.1.x,您应该使用beforeShow而不是afterLoad -
您好,感谢您回复 JFK。我草率地没有为此迭代更改 beforeShow。我想我已经解决了 .fancybox 的双重绑定,但我仍然遇到了问题。如果我删除了这个更新的小提琴的第 12-14 行 - jsfiddle.net/bzelip/EwbN8 - 那么 fancybox 会按计划工作(除了每组的图像计数)。我不知道我在生成图像计数显示的代码上做错了。
-
@BrianZ 你的 jsfiddle 都没有显示你的问题.. 你可能想要添加相关的 HTML 和样式。
-
@rahulmaindargi 感谢您愿意帮助和建议使用 jsfiddle。这是我第一次使用它,下次我一定会更好地使用它。