How to unbind fancybox from a selector

前提是你 提交于 2019-12-23 08:01:14

问题


I have an anchor link with a class which identifies it to be called on fancybox. example:

<a class="group">some code here</a>

Fancybox binding:

$('.group').fancybox();

If I want to unbind fancybox with elements selected by $('.group'), how should I do that? I have tried removeClass('group') but its not working.


回答1:


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



回答2:


You can add class "nofancybox" to link and this link will be ignored




回答3:


If you want to do it in javascript code, You may select the anchor tag object and remove the class.

Give an id to the element and call the removeClass method

<a id="noFancy" class="group">some code here</a>

Java Script

 $(function(){
     $("#noFancy").removeClass("group");

 });

If you have access to the HTML markup , why not just change to class to something else but with the same CSS values. then you dont need to execute the code to remove the class on documentready

HTML

<a class="groupNormal">I dont want fancybox</a>

CSS

.groupNormal
{
  // Put the CSS for group class
}



回答4:


Here is the solution that worked for me, however it does not unbind the fancybox in the sense of how the questioner would like to do it.

First, don't declare the fancybox on node, but bind the node to click event instead:

$(".classOfMiniImage").on("click", window.onImageMiniClicked);

In the handler, you can use your code to check conditions whether you need to display the fancybox or not, and then display it with explicit href reference:

window.onImageMiniClicked = function () {
    if (<your_condition>) {
        $.fancybox({
            'href': <link_to_full_size_image>,
            /* other options below */
            'transitionIn': 'elastic',
            'transitionOut': 'elastic',
            'speedIn': 600,
            'speedOut': 600,
            'overlayShow': true
        });
    }
}

Also, you can use a bit another approach and to unbind this handler manually if you don't need the fancybox on these items anymore:

$(".classOfMiniImage").off("click", window.onImageMiniClicked);

Hope it will help someone.



来源:https://stackoverflow.com/questions/8669804/how-to-unbind-fancybox-from-a-selector

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