jquery fadeout event listener

2019-08-07 09:38发布

问题:

I have an existing self coded accordian that i now need to attach an event listener to an existing fadeout event. Can I bind a new fadout listener to an existing one? And how is this done? Here is the accordian i a jsFiddle

回答1:

As others have said there isnt a fadeout event - you could create your own event though - you would add it to the callback for fadeout :

$(currentSlide).fadeOut("normal", function () {
    // your other code
    $(this).trigger('myFadeOutEvent');
});    

then you would need to listen for the event

 $('.class').on('myFadeOutEvent',function() {
    // do something
 });

See the docs for .trigger() for details



回答2:

FadeOut does not have an even listener. However, it has a callback, a function that fires after the fadeout is finished. The downside with this is that you will have to specify what should happen every time you use fadeout.

This has caused miles of code for me earlier.

$('.element').fadeOut(400,function () {
    //Whatever you want to do after the fade
});


回答3:

You can bind function to this element which you want to listen add do your fadout call your operation you want to apply as a call back function



回答4:

Refer to the doc http://api.jquery.com/fadeOut/

It says about 2 syntaxes .fadeOut( [duration] [, callback] ) and .fadeOut( [duration] [, easing] [, callback] )

You can apply any callback function