Unbind/Destroy fancybox 2 events

前端 未结 4 1869
孤城傲影
孤城傲影 2021-01-12 11:49

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 t

4条回答
  •  别那么骄傲
    2021-01-12 12:22

    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/

提交回复
热议问题