Unbind/Destroy fancybox 2 events

 ̄綄美尐妖づ 提交于 2019-12-01 04:00:30

If you include the attribute live:false then you will be able to remove the handlers from your elements using .off()

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.

For example:

$(".fancybox").attr('rel', 'gallery').fancybox({live: false});
//remove click handler
$('.fancybox').off("click.fb-start");

​ FYI In the documentation it says the following about live:

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

Here is a jsFiddle demonstrating

http://jsfiddle.net/DigitalBiscuits/DBvt7/211/

I know this is an old thread, but just wanted to confirm OAC Designs is absolutely right: Unbinding the .fancybox links only works if the live parameter is set to false.

However, you can also destroy Fancybox at the dom level, regardless of the live parameter, by doing:

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

Or

$(document).off("click.fb-start");


JSFiddle

Check out this JSFiddle for reference.

You can use this code to destroy fancybox functionality on links:

jQuery('a').unbind('click.fb').removeData('fancybox');

Thanks for the response, I have not tested the above, I used a different approach to resolve the issue.

What I did was instead of using the default Fancybox functionality I created functions for where I would need Fancybox and manually called Fancybox in each case which thus didn't bind the event.

This isn't the best approach and the above may be better but I will get to testing this in the new year :)

Thanks again.

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