3
A
回答
3
我制作了这个快速/简单的jQuery插件,可以让您按照自己的意愿进行操作。 :-)
$.fn.extend({
serial_fade: function(o) {
if(!o.speed || o.speed == undefined || o.speed == null) { o.speed = 'slow'; }
if(!o.fade || o.fade == undefined || o.fade == null) { o.fade = 'in'; }
if(!o.index || o.index == undefined || o.index == null) { o.index = 0; }
var s = this.selector;
if(o.fade.toLowerCase() == 'in') {
return this.eq(o.index).fadeIn(o.speed, function() {
o.index++;
if($(s).eq(o.index).length > 0) {
$(s).serial_fade({speed:o.speed,fade:o.fade,index:o.index});
}
});
} else {
return this.eq(o.index).fadeOut(o.speed, function() {
o.index++;
if($(s).eq(o.index).length > 0) {
$(s).serial_fade({speed:o.speed,fade:o.fade,index:o.index});
}
});
}
}
});
// To call it just do this:
$(ele).serial_fade({speed:'slow',fade:'in'});
// Optionally, you can pass which element you want to start with (0-based):
$('a').serial_fade({speed:'slow',fade:'in',index:2});
// If you want to start with element 2 (3, really) and fade all the rest *out*
// sequentially, verrry slowly:
$(ele).serial_fade({speed:5000,fade:'out',index:2});
它应该像任何其他jQuery方法一样使用任何类型的选择器。我希望这能为你解决。
编辑:我延长,以便它可以做淡入和褪色出局了。它似乎更有用的方式...
4
淡入有完成衰落时执行的回调。添加到elemX类的每个元素,其中x是衰落的顺序。然后使用下面的代码:
startFading(1);
function startFading(order) {
$(".ele" + order).fadeIn('slow', function() {
if (order < orderMax) {
startFading(order+1);
}
});
}
0
你可以使这个通用的,而不是强迫它只是为了淡化。
function depth(collection, fun, i) {
if (i === undefined)
depth(collection, fun, 0);
else
if (i < collection.length)
fun(collection[i], function(){
depth(collection, fun, i + 1);
});
};
depth($("a"), function(elem, fun) {
$(elem).fadeIn('slow', fun);
});
相关问题
- 1. 同步GM_xmlhttpRequest异步操作?
- 2. 执行同步操作
- 3. 同步(操作系统)
- 4. 操作和操作的同步和异步状态问题
- 5. 为什么要在同步操作中使用异步操作?
- 6. 当异步操作同步完成时?
- 7. 如何同步异步操作?
- 8. 使用RxJS同步异步操作
- 9. 了解同步和异步操作
- 10. Javascript异步和同步ajax操作
- 11. 异步操作中的异步操作
- 12. 如何使用java同步文件操作?同步或锁定?
- 13. 同一控制器中的异步和同步操作方法
- 14. 在链接期间允许同步操作的新jQuery API?
- 15. 如何使jQuery CSS操作同步(即没有回调)?
- 16. 将jquery操作与图像加载同步
- 17. 如何调用异步操作作为同步?
- 18. ASP.NET:为异步操作制作同步控制器
- 19. 使用@synchronized与同步操作
- 20. 同步eclipse保存操作规则
- 21. 同步操作问题RxJS observables订阅
- 22. FILE_FLAG_IO_BUFFERING减慢同步读取操作
- 23. Java在原子操作上同步
- 24. C中的同步写入操作
- 25. Gradle同步失败:操作超时
- 26. Perforce:如何取消同步操作?
- 27. OpenCL-GL互操作内存不同步
- 28. 异步操作,同时处理流
- 29. AFNetworking同步操作在NSOperationQueue iPhone上
- 30. 收集昂贵操作的Java同步
JavaScript中的递归!非常好。 – montrealist 2009-05-06 13:28:52
谢谢,这可以替换为同一类的元素。我看到你在使用订单。然而,这可以通过类 – Hitz 2009-05-06 14:05:34