2017-08-23 14 views
0

、あなたのコードを短くするための多数の方法があり、事前Fancybox再利用可能なコード

$(document).ready(function() { 
      $("a[rel=example_group]").fancybox({ 
       'transitionIn'  : 'none', 
       'transitionOut'  : 'none', 
       'titlePosition'  : 'over', 
       'titleFormat'  : function(title, currentArray, currentIndex, currentOpts) { 
        return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + '/' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>'; 
       } 
      }); 


      $("a[rel=example_group_crm]").fancybox({ 
       'transitionIn'  : 'none', 
       'transitionOut'  : 'none', 
       'titlePosition'  : 'over', 
       'titleFormat'  : function(title, currentArray, currentIndex, currentOpts) { 
        return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + '/' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>'; 
       } 
      }); 

      $("a[rel=example_group_human]").fancybox({ 
       'transitionIn'  : 'none', 
       'transitionOut'  : 'none', 
       'titlePosition'  : 'over', 
       'titleFormat'  : function(title, currentArray, currentIndex, currentOpts) { 
        return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + '/' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>'; 
       } 
      }); 

}); 

答えて

1

で感謝を私は1つのページに複数の空想箱を持っていますが、私はこれらすべてのファンシーbox.Pleaseヘルプを疥癬する1つの方法だけを作成したいです例えば、これらのリンクにいくつかのクラスを追加し、そのクラスをセレクタとして使用することができます。

​​

それとも、パラメータとしてセレクタを受信しfancyBoxを適用し、独自のメソッドを作成することができますか、このようなrel属性を持つリンクを選択するために、いくつかの正規表現を使用することができます。

+0

ありがとうございます –

関連する問題