1. sleep should not be used. javascript does not have multiple threads, and sleep will be blocked.
You can refer to this question to illustrate the principle that js is a single thread.
You should change your mind and use setInterval to implement loops ..
The code is as follows: |
Copy code |
$ ("# List div. left"). mouseover (function (){ Var item = $ (this). attr ("id "); // Alert (item ); T = setTimeout (function (){ $ ("#" + Item). parents ("div. oitem"). animate ({width: "292"}, 400 ); $ ("#" + Item). parents ("div. oitem"). siblings ("div"). animate ({width: "126"}, 400 ); },100 ); }). Mouseout (function (){ ClearTimeout (t ); }); |
2. Added a delay (time) in jquery 1.4, or the actual latency execution time is 1000 = 1 s.
The code is as follows: |
Copy code |
$ ("Button"). click (function (){ $ ("Div. first"). slideUp (300). delay (800). fadeIn (400 ); $ ("Div. second"). slideUp (300). fadeIn (400 ); }); . Delay (duration [, queueName]) |
The function can be directly used for the delay in the animation process. However, it does not have the callback parameter and cannot be used for timer.
Added to jQuery in version 1.4,. delay () method allows us to delay the execution of functions that follow it in the queue. it can be used with the standard effects queue or with a custom queue. only subsequent events in a queue are delayed; for example this will not delay the no-arguments forms. show () or. hide () which do not use the effects queue.
This is the description of the. delay () method in the JQuery document, that is, only the delayed events will be added to the delay () queue.