如何让jQuery等待效果完成? [英] How to get jQuery to wait until an effect is finished?

查看:73
本文介绍了如何让jQuery等待效果完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定有一天我读到了这本书,但似乎找不到任何地方.
我有一个fadeOut()事件,之后我删除了该元素,但是jQuery在有机会完成淡出之前删除了该元素.
我如何让jQuery等待元素淡出,然后然后删除它?

I am sure I read about this the other day but I can't seem to find it anywhere.
I have a fadeOut() event after which I remove the element, but jQuery is removing the element before it has the chance to finish fading out.
How do I get jQuery to wait until the element had faded out, then remove it?

推荐答案

您可以指定一个回调函数:

You can specify a callback function:

$(selector).fadeOut('slow', function() {
    // will be called when the element finishes fading out
    // if selector matches multiple elements it will be called once for each
});

此处的文档.

这篇关于如何让jQuery等待效果完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆