开发者

bind a jquery function to fancybox .close() event

开发者 https://www.devze.com 2023-02-27 16:25 出处:网络
I would like to trigger a simple jQuery function based on a fancybox closing. it is the only fancybox on the page

I would like to trigger a simple jQuery function based on a fancybox closing. it is the only fancybox on the page

$.fn.fancybox.c开发者_Python百科lose = function() {
    $('#sub_cont').hide(250, function() {
    $('#IDsearchform input').val('');
    });
 });

ofcourse the above doesn't work


*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

Pass the onClosed option to the fancybox function.

i.e:

$("<YOUR-SELECTOR>").fancybox({
  onClosed: function() {
    $('#sub_cont').hide(250, function() {
    $('#IDsearchform input').val('');
    });
  })
});


Just a note. It looks like Fancybox 2 depreciated the onClosed callback. It now uses afterClose.

See the new documentation under 'Callbacks'. http://fancyapps.com/fancybox/


In latest version of fancybox you might need to use 'afterClose' in place of '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('');
    });
  })
});


$("#myfancybox").fancybox({
    'onClosed'  : function() {
             $('#sub_cont').hide(250, function() {
                $('#IDsearchform input').val('');
             });
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消