.children()和.fadeOut()的jquery问题
我想获得一个div的所有子对象,将它们淡出,然后在div中插入一些文本。我在fadeOut()中使用回调函数,以便动画平滑:.children()和.fadeOut()的jquery问题,jquery,Jquery,我想获得一个div的所有子对象,将它们淡出,然后在div中插入一些文本。我在fadeOut()中使用回调函数,以便动画平滑: var foo = $(this).parents('.foo').eq(0); foo.children().fadeOut(300,function() { foo.prepend('some text'); }); 问题是淡出似乎是按顺序对每个子项进行激发,而不是一次对所有子项进行激发-有三个子项,因此回调函数为每个子项激发,从而产生插入文本的三个实例。我可以
var foo = $(this).parents('.foo').eq(0);
foo.children().fadeOut(300,function() {
foo.prepend('some text');
});
问题是淡出似乎是按顺序对每个子项进行激发,而不是一次对所有子项进行激发-有三个子项,因此回调函数为每个子项激发,从而产生插入文本的三个实例。我可以把所有的孩子都放在一个div中,然后淡出,但是如果可以的话,我想避免添加更多的标记。还有其他方法吗?删除子项()
并直接调用foo
或者,在回调中
function() {
if ($(this).siblings(':animated').length) {
return;
}
// What you need to do once only :)
}
.请尝试以下代码:
var foo = $(this).parents('.foo').eq(0);
foo.fadeOut(300,function() {//fade out foo
foo
.children().hide().end()//set display none to foo's children
.prepend('some text').show();//prepend text to foo and show it (but children have display none)
});