jquery fadeout event listener

∥☆過路亽.° 提交于 2019-12-24 16:31:05

问题


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



来源:https://stackoverflow.com/questions/10598089/jquery-fadeout-event-listener

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