Example of jquery delayed processing and regular execution code

Source: Internet
Author: User
Tags sleep

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.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.