取消绑定/销毁fancybox 2事件 [英] Unbind/Destroy fancybox 2 events
问题描述
我遇到一个奇怪的问题,我的代码可以通过Ajax提取内容,然后将Fancybox(2)绑定到某些元素.问题是,当我刷新"此页面时,我会调用相同的函数来再次拉动并绑定Fancybox.
I am having a strange issue, I have code that pulls content via ajax and then binds Fancybox (2) to certain elements. The issue is that when I "refresh" this page I call the same function that pulls and binds Fancybox again.
在更改为Fancybox 2之前,我一直使用的常规方法是取消绑定元素并重新绑定它们.但是,这似乎不适用于FB2.
My normal approach that has been working up until I changed to Fancybox 2 is to unbind the elements and rebind them. This however does not seem to be working with FB2.
我尝试了以下操作:
$('.tool_button').unbind('click.fb');
$('.tool_button').unbind('click');
$('.tool_button').unbind();
$('.tool_button').off('click.fb');
$('.tool_button').off('click');
$('.tool_button').off();
我确实在源文件中注意到了以下内容(可能从652行开始):
I did notice the following in the source file which may be of use (starting line 652):
// Unbind the keyboard / clicking actions
unbindEvents: function () {
if (F.wrap && isQuery(F.wrap)) {
F.wrap.unbind('.fb');
}
D.unbind('.fb');
W.unbind('.fb');
}
如果有人可以在这里提供帮助,将不胜感激.
If anyone could help here it would be much appreciated.
先谢谢了. 尼克
推荐答案
如果包含属性live:false
,则可以使用.off()
If you include the attribute live:false
then you will be able to remove the handlers from your elements using .off()
在仔细研究了源代码之后,我还发现,如果要专门针对特定事件,则该特定事件为click.fb-start
.
After digging through the source code i've also found that the specific event is click.fb-start
, if you want to target it specifically.
例如:
$(".fancybox").attr('rel', 'gallery').fancybox({live: false});
//remove click handler
$('.fancybox').off("click.fb-start");
仅供参考,在文档中它对live
说了以下内容:
FYI In the documentation it says the following about live
:
实时:如果设置为true,fancyBox将使用实时".触发点击事件.设置 "false"(如果您只需要应用于当前集合),例如 使用类似-$("#page").children().filter('a').eq(0).fancybox();
live: If set to true, fancyBox uses "live" to assing click event. Set to "false", if you need to apply only to current collection, e.g., if using something like - $( "#page" ).children().filter('a').eq(0).fancybox();
jsFiddle
这是一个jsFiddle演示
jsFiddle
Here is a jsFiddle demonstrating
http://jsfiddle.net/DigitalBiscuits/DBvt7/211/
这篇关于取消绑定/销毁fancybox 2事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!