将 jquery 函数绑定到fancybox .close() 事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5751538/
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
bind a jquery function to fancybox .close() event
提问by iamwhitebox
I would like to trigger a simple jQuery function based on a fancybox closing. it is the only fancybox on the page
我想基于fancybox 关闭触发一个简单的jQuery 函数。它是页面上唯一的fancybox
$.fn.fancybox.close = function() {
$('#sub_cont').hide(250, function() {
$('#IDsearchform input').val('');
});
});
ofcourse the above doesn't work
当然以上是行不通的
回答by Chandu
*Update: *Please take a note of @mathoiland's answer, "It looks like Fancybox 2 deprecated the onClosed callback. It now uses afterClose." if you are using FancyBox 2.x
*更新: *请注意@mathoiland 的回答,“看起来 Fancybox 2 不推荐使用 onClosed 回调。它现在使用 afterClose。” 如果您使用的是 FancyBox 2.x
Pass the onClosed option to the fancybox function.
将 onClosed 选项传递给fancybox 函数。
i.e:
IE:
$("<YOUR-SELECTOR>").fancybox({
onClosed: function() {
$('#sub_cont').hide(250, function() {
$('#IDsearchform input').val('');
});
})
});
回答by matthoiland
Just a note. It looks like Fancybox 2 depreciated the onClosed callback. It now uses afterClose.
只是一个注释。看起来 Fancybox 2 贬低了 onClosed 回调。它现在使用 afterClose。
See the new documentation under 'Callbacks'. http://fancyapps.com/fancybox/
请参阅“回调”下的新文档。http://fancyapps.com/fancybox/
回答by Vinod K
In latest version of fancybox you might need to use 'afterClose' in place of 'onClosed'
在最新版本的fancybox中,您可能需要使用“afterClose”代替“onClosed”
so this code..
所以这个代码..
$("<YOUR-SELECTOR>").fancybox({
onClosed: function() {
$('#sub_cont').hide(250, function() {
$('#IDsearchform input').val('');
});
})
});
should become ...
应该变成...
$("<YOUR-SELECTOR>").fancybox({
afterClose: function() {
$('#sub_cont').hide(250, function() {
$('#IDsearchform input').val('');
});
})
});
回答by Matt
$("#myfancybox").fancybox({
'onClosed' : function() {
$('#sub_cont').hide(250, function() {
$('#IDsearchform input').val('');
});
}
});