【问题标题】:fancybox image count title displayfancybox 图像计数标题显示
【发布时间】: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。这是我第一次使用它,下次我一定会更好地使用它。

标签: jquery fancybox


【解决方案1】:

你的脚本的问题是这一行

beforeShow: function () {
    this.title = (this.title ? " + this.title + '<br />' : ") + 'Image ' + (this.index + 1) + ' of ' + this.group.length;
}

你说你在关注我的帖子 here 但我的代码中的同一行看起来像:

beforeShow: function () {
    this.title = (this.title ? '' + this.title + '<br />' : '') + 'Image ' + (this.index + 1) + ' of ' + this.group.length;
}

你是否足够敏锐地看到差异? ...所以让我们以相同的顺序将它们并排放置(仅相关部分):

this.title = (this.title ? " + this.title + '<br />' : ")   // you
this.title = (this.title ? '' + this.title + '<br />' : '') // me

我的脚本中的单引号创建了一个空格,而您的双引号创建了一个不应该存在的字符串。

【讨论】:

  • 谢谢,现在一切正常。在此处发布之前,我尝试了多个带有单引号和双引号的版本,但均无济于事。非常感谢您的帮助。
  • @JFK 对此有什么想法吗? stackoverflow.com/questions/30994366/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多