【发布时间】:2012-03-10 14:28:43
【问题描述】:
我正在尝试为一组 div 元素(比如说 50 个)运行以下动画,但是,$.each() 函数仅适用于数组中的第一个元素。
$.each(droplets, function(){
splashVanish(this);
});
function splashVanish(droplet) {
droplet.fadeOut(500, function(){
droplet.css({'top':Math.random()*600+'px','left':Math.random()*1400+'px'});
droplet.remove();
$("body").append(droplet);
//recursive call for infinite animation time
droplet.fadeIn(500,function(){splashVanish(droplet)});
});
}
当上面的代码运行时,只有数组中的第一个divfadesOut,随机位置和fadesIn 无限动画持续时间。可悲的是,所有其他 49 个divs 都是静态的,并且没有执行相同的功能。
【问题讨论】:
-
什么是dropplet?它是一个 jQuery 对象吗?什么是液滴? jQ 对象的集合?某种数组?
-
对不起,我没有说清楚..它只是一个
div元素 -
强烈感觉
this是$.each回调中的整个集合,而jquery doc 声明它应该是每个调用的当前值。您是否尝试过在此处设置断点并检查this值? -
哦,我明白了,所以你的意思是,
this而不是$(this)指向集合本身?
标签: jquery css animation recursion infinite