When we need to execute several functions consecutively and these functions will operate on page elements all the time, it is very likely that the page will have a short card, and then all the information will pop up suddenly.
Generally, setTimeout (FN, 0) is used for execution. In fact, for JS setTimeout, especially for IE6, the response time is about 17 milliseconds at the earliest. Therefore, it is set to 0, not significant.
Moreover, this approach is discontinuous and non-coherent. Therefore, I wrote a simple one myself.
1 /**
2 * @ author floyd
3 * @ name: asynchronous processing of event queues
4 * @ example var qe = new QueneEnginer (); qe. add (fn, context, arrParam); qe. start ();
5 */
6
7 var QueneEnginer = function (){
8
9 this. Quene = [];
10}
11 QueneEnginer. prototype = {
12 processTime: 20,
13 /**
14 * add events to the queue
15 * @ param {function} fn function object
16 * @ param {object} context object can be empty
17 * @ param {array} the array of arrParam parameters can be empty.
18 */
19 add: function (fn, context, arrParam ){
20
21 this. Quene. push (
22 {
23 fn: fn,
24 context: context,
25 param: arrParam
26}
27 );
28 },
29 start: function (){
30 var that = this;
31 setTimeout (function () {that. process () ;}, that. processTime );
32 },
33 process: function (){
34
35 var quene = this. Quene. shift ();
36
37 If (! Quene) return;
38
39 quene. FN. Apply (quene. Context, quene. Param );
40
41 quene = NULL;
42
43 This. Start ();
44}
45}