$("#home #oneTool").prepend($(".userInfo.module"));
var topVal = $(".userInfo.module").height();
$(".userInfo.module").hide();
$(".userInfo.module").slideDown(3000);
$("#home #oneTool div.divspot").each(function(){
var newVal = topVal + parseInt($(this).css('top'));
$(this).css('top',newVal);
});
.userInfo.module
出现在所有 div.divspot
...
由于我使用的是 slideDown,所以每个函数都需要延迟,这样 div.divspot
也可以平滑地向下滑动..(延迟会有帮助吗?)
注意所有的div.divspot
都是绝对定位的
最佳答案
首先,slideDown 将一个函数作为参数,在它完成后调用。 http://api.jquery.com/slideDown/
支持另一个知道你在问什么的回答者,并因为我没有正确阅读你的问题而对我说#fail。
也就是说,对于完成后没有回调的方法,这里有几个选项。
两种选择:
- 使用队列
- 使用设置超时
使用队列:
$(".userInfo.module").fooThatTakes(3000).queue(function() {
$("#home #oneTool div.divspot").each(function(){
var newVal = topVal + parseInt($(this).css('top'));
$(this).css('top',newVal);
});
});
使用 setTimeout。
var delay = 3000;
$(".userInfo.module").fooThatTakes(delay);
t = setTimeout(afterFoo, delay);
function afterFoo() {
$("#home #oneTool div.divspot").each(function(){
var newVal = topVal + parseInt($(this).css('top'));
$(this).css('top',newVal);
});
}
关于javascript - 如何将 delay() 与 each() 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6674976/