【问题标题】:Stop Fancybox 1.3 from closing when clicking outside image单击外部图像时阻止 Fancybox 1.3 关闭
【发布时间】:2013-03-11 03:06:50
【问题描述】:

我之前搜索并发现了一些关于此的问题,但没有一个答案有效。 我想要它做的不是在我单击图像外部时关闭,而只是在单击角落的 X 时关闭。

我尝试了很多不同的想法,有些只是在同一帧中打开图像,而有些则有效,只是现在角落的 X 消失了,所以我根本无法关闭它。

让我最接近的是“modal:true”,但 X 使用它消失了。

这是我的页面,图片位于菜单中的“Fotografier”下: http://esoxluciusdegothia.blogg.se

Fancybox 的代码是:

<script type="text/javascript">
    $(document).ready(function() {
        $(".fancybox").fancybox();
    });
</script>

正如我所说,我尝试的大多数“答案”只是让图片在同一个窗口中打开,就像它是图片的直接链接一样。我希望他们弹出并获得导航按钮+关闭按钮

【问题讨论】:

    标签: jquery html fancybox


    【解决方案1】:

    对于fancybox v1.3.x,请使用以下 API 选项:

    <script type="text/javascript">
        $(document).ready(function() {
            $(".fancybox").fancybox({
               "hideOnOverlayClick" : false, // prevents closing clicking OUTSIE fancybox
               "hideOnContentClick" : false, // prevents closing clicking INSIDE fancybox
               "enableEscapeButton" : false  // prevents closing pressing ESCAPE key
            });
        });
    </script>
    

    ...所以关闭fancybox的唯一方法是按下close按钮。

    【讨论】:

      【解决方案2】:

      编辑:这个答案与fancyBox 2有关。有关fancyBox 1.3的方式,请参见JFK's answer

      如果您查看 fancyBox 代码,您会注意到 modal 设置只是一个快捷方式:

      // 'modal' propery is just a shortcut
      if (coming.modal) {
          $.extend(true, coming, {
              closeBtn   : false,
              closeClick : false,
              nextClick  : false,
              arrows     : false,
              mouseWheel : false,
              keys       : null,
              helpers: {
                  overlay : {
                      closeClick : false
                  }
              }
          });
      }
      

      在你的情况下,你想要的是:

      $('.fancybox').fancybox({
          helpers: {
              overlay: {
                  closeClick: false
              }
          }
      });
      

      【讨论】:

      • 如果你仔细阅读问题的标题,它会说 "...Fancybox 1.3 ...";不过,对于 v2.x,您的答案是可以的。
      • 谢谢,我在答案的顶部添加了一条注释。不过我保留了它,该信息可能对某些人有用。最后一个 fancyBox 1 是 2010 年的,也许是时候转移到 fancyBox 2 了 ;-)
      • maybe it is time to move to fancyBox 2 :人们可能不想迁移到 v2.x,因为它的 licensing scheme
      • ... 而对于 v2.x,自 2011 年 12 月以来已经在此处stackoverflow.com/a/8404587/1055987 得到回答;)
      • 关于许可的要点。作为参考,fancyBox 1 在双重 MIT/GPL 下。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-01
      • 1970-01-01
      • 2012-04-04
      相关资源
      最近更新 更多