2013-05-21 73 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