简体   繁体   English

jQuery淡出事件监听器

[英]jquery fadeout event listener

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? 我可以将新的Fadout侦听器绑定到现有的侦听器吗? And how is this done? 怎么做? Here is the accordian ia jsFiddle 这是手风琴ia jsFiddle

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 : 正如其他人所说,没有fadeout事件-您可以创建自己的事件-将其添加到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 有关详细信息, 请参阅文档.trigger()

FadeOut does not have an even listener. FadeOut没有均匀的侦听器。 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
});

您可以将函数绑定到要侦听的该元素上,然后进行淡出调用,将要用作回调函数的操作

Refer to the doc http://api.jquery.com/fadeOut/ 请参阅文档http://api.jquery.com/fadeOut/

It says about 2 syntaxes .fadeOut( [duration] [, callback] ) and .fadeOut( [duration] [, easing] [, callback] ) 它说了大约两种语法.fadeOut( [duration] [, callback] ).fadeOut( [duration] [, easing] [, callback] )

You can apply any callback function 您可以应用任何回调函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM