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