如何禁用Facebox(jQuery) [英] how to disable facebox (jquery)

查看:94
本文介绍了如何禁用Facebox(jQuery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在某些链接上使用facebox插件.

I use facebox plugin on certain links.

我想动态禁用某些链接.因此单击它们将不会打开Facebox.

I want to disable some of the links dynamically. so clicking them will not open facebox.

我尝试了几种方法来执行此操作,但似乎都没有用.单击链接时,Facebox仍然有效.

I tried several ways to do it but none of them seem to work. Facebox still works when clicking on the links.

我什至尝试了此操作(防止了click和mouse down事件),但仍然不能阻止Facebox弹出.

I even tried this (prevent the click and mouse down events) but it still doesn't disable the facebox from popping up.

$('#who_button').click(function(event) {  event.preventDefault();});
$('#who_button').mousedown(function(event) {  event.preventDefault();});

我该怎么办?

按照brad和PetersenDidIt的建议,我尝试了以下方法:

Following brad and PetersenDidIt advice I tried this:

$('#who_button').click(function(event) { alert ('here');event.stopPropagation(); event.stopImmediatePropagation();});
    $('#who_button').mousedown(function(event) { event.stopPropagation(); event.stopImmediatePropagation();});

而且仍然没有运气.此外,我看到在警报对话框下出现了面框.这意味着Facebox在我的click/mousedown事件被调用之前就开始了.

AND still no luck. Moreover I see that the facebox frame appears under the alert dialog. which means that facebox starts before my click/mousedown events are even called.

是否可以附加将在所有其他事件之前发生的事件?

Is it possible to attach event which will occur before all other events?

也许facebox使用了另一个事件(不是单击或鼠标按下).会是什么?

Perhaps facebox uses another event (not click or mousedown). what can it be?

推荐答案

preventDefault仅阻止该点击的正常行为(即,重定向到链接).

preventDefault just prevents whatever the normal behaviour of that click is (ie redirect on a link).

我从没使用过facebox,所以我不确定它如何绑定事件,但是您可能想要一些类似的东西:

I've never used facebox, so I'm not sure how it binds its events, but you probably want some thing more like:

event.stopImmediatePropagation()

编辑

貌似Facebox使用它自己的自定义事件.您可以在源代码中(下面)看到它.因此,最好的选择是从该事件中取消绑定您的元素:

Looks like facebox uses it's own custom event. You can see this in the source (below). So your best bet is to unbind your element from that event:

$("ele").unbind("click.facebox");

Facebox公共功能

Facebox public function

  $.fn.facebox = function(settings) {
    if ($(this).length == 0) return

    init(settings)

    function clickHandler() {
      $.facebox.loading(true)

      // support for rel="facebox.inline_popup" syntax, to add a class
      // also supports deprecated "facebox[.inline_popup]" syntax
      var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
      if (klass) klass = klass[1]

      fillFaceboxFromHref(this.href, klass)
      return false
    }

    return this.bind('click.facebox', clickHandler)
  }

这篇关于如何禁用Facebox(jQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆