2013-05-21 69 views
0

我有一个页面,使用fancybox 2.1.4显示多个不同的图像画廊,根据其各自的rel属性。fancybox图像计数标题显示

我一直在努力获取当前图像标题中显示的每个图库的图像数量。在复制由JFK通过this Stack Overflow post描述的方法之后,其余脚本将变为禁用状态。

我的代码如下。谁能帮忙?

<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> 
+1

jsfiddle.net请 –

+0

这里是一个小提琴:http://jsfiddle.net/bzelip/HGxHg/ –

+0

你绑定选择器'.fancybox'到fancybox两次,所以第二个覆盖第一个。此外,您应该使用'beforeShow'而不是'afterLoad' for v2.1.x – JFK

回答

0

与你的脚本的问题是这条线

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 

在我的脚本中的单引号创建一个空的空间,而你的双引号创建一个字符串,它不该不在那里。

+0

谢谢,现在一切正常。在尝试发布之前,我尝试了单引号和双引号的多个版本,但无济于事。我非常感谢你的帮助。 –

+0

@JFK对此有何看法? http://stackoverflow.com/questions/30994366/changing-the-thumbs-position-responsiveness-in-fancybox – mikeb