javascript 如何从选择器中取消绑定fancybox
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8669804/
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 unbind fancybox from a selector
提问by Ranoy
I have an anchor link with a class which identifies it to be called on fancybox. example:
我有一个带有类的锚链接,该类标识要在fancybox 上调用它。例子:
<a class="group">some code here</a>
Fancybox binding:
Fancybox 绑定:
$('.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.
如果我想用 $('.group') 选择的元素解除fancybox,我应该怎么做?我试过了,removeClass('group')
但它不工作。
回答by lafeber
$('.group').unbind('click.fb')
回答by Pavel Kukla
You can add class "nofancybox" to link and this link will be ignored
您可以将类“nofancybox”添加到链接中,此链接将被忽略
回答by Eadel
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.
这是对我有用的解决方案,但是它并没有解除对发问者希望如何做的fancybox的绑定。
First, don't declare the fancybox on node, but bind the node to click
event instead:
首先,不要在节点上声明fancybox,而是将节点绑定到click
事件:
$(".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:
在处理程序中,您可以使用代码检查是否需要显示fancybox 的条件,然后使用显式href
引用显示它:
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:
此外,如果您不再需要这些项目上的fancybox,您可以使用另一种方法并手动取消绑定此处理程序:
$(".classOfMiniImage").off("click", window.onImageMiniClicked);
Hope it will help someone.
希望它会帮助某人。
回答by Shyju
If you want to do it in javascript code, You may select the anchor tag object and remove the class.
如果您想在 javascript 代码中执行此操作,您可以选择锚标记对象并删除该类。
Give an id to the element and call the removeClass method
给元素一个id并调用removeClass方法
<a id="noFancy" class="group">some code here</a>
Java Script
Java脚本
$(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 标记,为什么不将类更改为其他内容但具有相同的 CSS 值。那么你不需要执行代码来删除 documentready 上的类
HTML
HTML
<a class="groupNormal">I dont want fancybox</a>
CSS
CSS
.groupNormal
{
// Put the CSS for group class
}