How to destroy Fancybox?

我是研究僧i 提交于 2019-12-22 03:18:20

问题


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?

This doesn't work:

$("a").unbind('fancybox').unbind('click');

Testing code: http://jsfiddle.net/martinba/yy3cw/2/

I use current version 2.1.4.


回答1:


In order to unbind fancybox you have to unbind events under fb-start namespace from document:

$(document).unbind('click.fb-start');

Though, I don't know why developer made it so unobvious.

http://jsfiddle.net/dfsq/yy3cw/16/




回答2:


Try to call:

.unbind('click.fb') to unbind fancybox.

like:

$('.group').unbind('click.fb')



回答3:


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');



回答4:


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



来源:https://stackoverflow.com/questions/15154522/how-to-destroy-fancybox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!