简体   繁体   English

这两种执行回调(jQuery)的方式之间有区别吗?

[英]Is there a difference between this two ways of doing callbacks (jQuery)?

I'm just starting to learn jQuery and I've seen this. 我刚刚开始学习jQuery,我已经看到了。 I don't know if there is any difference or which one would be better. 我不知道是否有任何区别,或者哪个更好。

myDiv.fadeOut('fast', function() {
    myDiv.removeClass('slide');
});

And

myDiv.fadeOut('fast').removeClass('slide');

The callback to .fadeOut call fires when fade out finishes. 淡出完成时,将触发对.fadeOut调用的回调。 So this 所以这

myDiv.fadeOut('fast', function() {
    myDiv.removeClass('slide');
});

will remove the class at the end of animation while this: 将在动画结束时删除该类,同时:

myDiv.fadeOut('fast').removeClass('slide');

removes the class after .fadeOut is initialized, basically at the begining of the animation. 基本上在动画开始时,在初始化.fadeOut之后删除该类。

There is no answer to the question "which is better?" 对于“哪个更好?”这个问题没有答案。 because these two are functionally different. 因为这两个在功能上是不同的。 That totally depends on what you are trying to achieve. 这完全取决于您要实现的目标。

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

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