jQuery Async Plugin
This plugin allows to easily code very long-lasting loops in an asynchronous way to avoid losing the browser responsiveness.
jQuery.whileAsync(opts)
This function ease the building of an asynchronnous loop with a while structure.
- opts
-
- test
- (default: returns true) function to execute for the test part of the while loop
- loop
- (default: nothing) function to execute as the loop body
- end
- (default: nothing) function to execute at the end of the loop iteration
- delay
- (default: 10) delay in milliseconds between each asynchronous calls
- bulk
- (default: 500) maximum delay in milliseconds the loop is allowed to run without any asynchronous calls. 0 to disable.
var test = jQuery('#TestWhile');
test.empty();
var n = 10;
jQuery.whileAsync({
delay: 100,
bulk: 0,
test: function() { return n > 0 },
loop: function()
{
test.text(test.text() + ' ' + n);
n--;
},
end: function()
{
test.text(test.text() + ' END');
}
})
jQuery.eachAsync(array, opts)
This function ease the building of a for-each loop.
- array
- array or array-like to use for the iteration
- opts
-
- loop
- function(index, value) (default: nothing) function to execute as the loop body
- end
- function() (default: nothing) function to execute at the end of the loop iteration
- delay
- (default: 10) delay in milliseconds between each asynchronous calls
- bulk
- (default: 500) maximum delay in milliseconds the loop is allowed to run without any asynchronous calls. 0 to disable.
var test = jQuery('#TestEach');
test.empty();
var n = 10;
jQuery.eachAsync([1,2,3,4,5,6,7,8,9,10], {
delay: 100,
bulk: 0,
loop: function(index, value)
{
test.text(test.text() + ' ' + value);
},
end: function()
{
test.text(test.text() + ' END');
}
})
jQuery.fn.eachAsync(opts)
This function is the same as jQuery.eachAsync() but works directly on a jQuery.
- opts
-
- loop
- function(index, value) (default: nothing) function to execute as the loop body
- end
- function() (default: nothing) function to execute at the end of the loop iteration
- delay
- (default: 10) delay in milliseconds between each asynchronous calls
- bulk
- (default: 500) maximum delay in milliseconds the loop is allowed to run without any asynchronous calls. 0 to disable.
var n = 10;
jQuery('#TestFnEach span').empty().eachAsync({
delay: 100,
bulk: 0,
loop: function(index)
{
jQuery(this).text(index+' ');
}
})
출처 : http://mess.genezys.net/jquery/jquery.async.php
'소프트웨어 > JavaScript • Dhtml' 카테고리의 다른 글
HTML5.js (0) | 2009.07.08 |
---|---|
JSON javascript 읽기 (0) | 2009.07.03 |
Masked Input plugin (0) | 2009.06.29 |
JSON API 하이재킹, Ajax Security (0) | 2009.05.21 |
Javascript Packer & 암호화 - C# (0) | 2008.06.30 |