javascript 如何摧毁 Fancybox?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15154522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to destroy Fancybox?
提问by Martin
I'm trying to destroy Fancybox. I haven't found any method to do it in documentation. How to destroy it after it was initialized?
我试图摧毁Fancybox。我还没有在文档中找到任何方法来做到这一点。初始化后如何销毁?
This doesn't work:
这不起作用:
$("a").unbind('fancybox').unbind('click');
Testing code: http://jsfiddle.net/martinba/yy3cw/2/
测试代码:http: //jsfiddle.net/martinba/yy3cw/2/
I use current version 2.1.4.
我使用当前版本 2.1.4。
回答by dfsq
In order to unbind fancybox you have to unbind events under fb-start
namespace from document
:
为了解绑fancybox,你必须解绑fb-start
命名空间下的事件document
:
$(document).unbind('click.fb-start');
Though, I don't know why developer made it so unobvious.
虽然,我不知道为什么开发人员让它如此不明显。
回答by CloudyMarble
Try to call:
尝试调用:
.unbind('click.fb')
to unbind fancybox.
.unbind('click.fb')
解开fancybox。
like:
喜欢:
$('.group').unbind('click.fb')
回答by Passer by
You can unbind every fancy box by running:
您可以通过运行以下命令解除绑定每个花哨的盒子:
$(document).unbind('click.fb-start');
Or if you need to unbind a specific selector, you can undelegate it:
或者,如果您需要取消绑定特定选择器,您可以取消委托:
var selector = 'a.my-fancy-box';
selector = selector + ":not('.fancybox-item, .fancybox-nav')";
$(document).undelegate(selector, 'click.fb-start');
Or alternatively:
或者:
// Bind
$('a.my-fancy-box').fancybox({live: false});
// Unbind
$('a.my-fancy-box').unbind('click.fb');
回答by Pinny
As it was mentioned here earlier: $(document).unbind('click.fb-start');
But you also might want to add this option to the fancybox init call: live:false
正如前面提到的:$(document).unbind('click.fb-start');
但您可能还想将此选项添加到fancybox init 调用中:live:false