Aar*_*ron 0 jquery jquery-chaining jquery-animate
我正在尝试将匹配的东西组合起来:
$(".item").each(function(i) {
//animation here
});
Run Code Online (Sandbox Code Playgroud)
使用jQuery固有的链接功能,强制动画等待上一个动画完成,例如:
$(".item").each(function(i) {
$(this).animate({marginLeft:"0"}, 60);
});
Run Code Online (Sandbox Code Playgroud)
然后在动画完成后触发.load函数.基本上,我想按顺序淡出四个项目[一个接一个,而不是一次全部],然后将四个新项目加载到同一个div中,替换前四个.
我怎样才能以可重用/可变的方式做到这一点?
如何检查元素是否是最后一个然后添加回调?
$(".item").each(function(i, elem) {
var callback = $(elem).is(':last') ? function() {
//dosomething
} : function(){};
$(this).animate({marginLeft:"0"}, {duration: 60, complete: callback);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8440 次 |
| 最近记录: |