Javascript Fancybox可重用代码

Javascript Fancybox可重用代码,javascript,jquery,fancybox,Javascript,Jquery,Fancybox,我有多个花式盒子在一个页面上,但我只想创建一个方法来管理所有这些花式盒子。请帮助提前感谢 $(document).ready(function() { $("a[rel=example_group]").fancybox({ 'transitionIn' : 'none', 'transitionOut' : 'none', 'titlePosition'

我有多个花式盒子在一个页面上,但我只想创建一个方法来管理所有这些花式盒子。请帮助提前感谢

  $(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>';
                }
            });

 });
$(文档).ready(函数(){
$(“a[rel=example\u group]”)。fancybox({
“transitionIn”:“无”,
“transitionOut”:“无”,
“标题位置”:“结束”,
“标题格式”:函数(标题、currentArray、currentIndex、currentOpts){
返回'Image'+(currentIndex+1)+'/'+currentArray.length+(title.length?''+title:'')+'';
}
});
$(“a[rel=example\u group\u crm]”)({
“transitionIn”:“无”,
“transitionOut”:“无”,
“标题位置”:“结束”,
“标题格式”:函数(标题、currentArray、currentIndex、currentOpts){
返回'Image'+(currentIndex+1)+'/'+currentArray.length+(title.length?''+title:'')+'';
}
});
$(“a[rel=example\u group\u human]”)({
“transitionIn”:“无”,
“transitionOut”:“无”,
“标题位置”:“结束”,
“标题格式”:函数(标题、currentArray、currentIndex、currentOpts){
返回'Image'+(currentIndex+1)+'/'+currentArray.length+(title.length?''+title:'')+'';
}
});
});

缩短代码的方法有很多,例如,您可以在这些链接中添加一些类,并将该类用作选择器。或者您可以使用一些regexp来选择具有
rel
属性的链接,如下所示:

$("a[rel^=example_group]").fancybox({
   // your parameters
});
或者,您可以创建自己的方法,该方法接收选择器作为参数,然后应用fancyBox