首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Fancybox可重用代码

Fancybox可重用代码
EN

Stack Overflow用户
提问于 2017-08-23 23:08:09
回答 1查看 37关注 0票数 0

我在一个页面上有多个精美的方框,但我只想创建一个方法来管理所有这些精美的box.Please帮助,提前谢谢

代码语言:javascript
复制
  $(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>';
                }
            });

 });
EN

回答 1

Stack Overflow用户

发布于 2017-08-23 23:31:55

有许多方法可以缩短您的代码,例如,您可以向这些链接添加一些类,并使用该类作为选择器。或者您可以使用一些正则表达式来选择具有rel属性的链接,如下所示:

代码语言:javascript
复制
$("a[rel^=example_group]").fancybox({
   // your parameters
});

或者,您可以创建自己的方法,该方法将选择器作为参数接收,然后应用fancyBox。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45843396

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档