我可以延迟jQuery addClass吗? [英] Can I delay jQuery addClass?
本文介绍了我可以延迟jQuery addClass吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种方法可以延迟jQuery的addClass()
?例如此代码
Is there a way to delay the addClass()
of jQuery? For example this code
$('#sampleID').delay(2000).fadeOut(500).delay(2000).addClass('aNewClass');
当我加载页面时,它的ID为"sampleID"上已经有类"aNewClass".如何解决这个问题呢?我想要的是addClass将在fadeOut()
结束后发生.
When I load the page, it has the class 'aNewClass' already on id 'sampleID'. How to solve this problem? What I want is the addClass will happen after it ended the fadeOut()
.
推荐答案
我想要的是addClass 发生在 fadeOut()结束之后.
What I want is the addClass will happen after it ended the fadeOut().
您可以使用对fadeOut
的回调函数,如下所示:
You can use callback function to fadeOut
like this:
$('#sampleID').fadeOut(500, function(){
$(this).addClass('aNewClass');
});
这篇关于我可以延迟jQuery addClass吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文