Jquery delayed execution example _ jquery-js tutorial

Source: Internet
Author: User
Delayed execution is quite useful in some special cases, and the implementation method is also very simple. This article provides a good example. If you need it, you can refer to it and hope to help you. The Code is as follows:


$ (Function (){
Var $ inputs = $ ('input [type = button] ')
. Delay (500)
. Queue (function () {$ (this). hide (). dequeue ();})
. Delay (1500)
. Queue (function () {$ (this). show ();});
});


The code above hides the buttons on the page in 500 milliseconds after the page is loaded, and then displays them in 1500 milliseconds.

The Code is as follows:


$ (Function (){
Var $ inputs = $ ('input [type = button] ')
. Delay (500)
. Queue (function () {$ (this). hide (). dequeue ();})
. Delay (1500)
. Show (1 );
//. Queue (function () {$ (this). show ();});
});


The above code works the same as the previous code.

The Code is as follows:


$ (Function (){
Var $ inputs = $ ('input [type = button] ')
. Delay (500)
. Queue (function () {$ (this). hide ();})
. Delay (1500)
. Show (1 );
//. Queue (function () {$ (this). show ();});
});


The above code is also hidden and will not be displayed. Compared with Code 2, the code in the queue does not call dequeue. Therefore, after the queue is executed, the animation queue is suspended, you need to call dequeue to execute it (here, the hide () in queue is not an animation, but the animation of the current object will also be executed in queue ).

The Code is as follows:


$ (Function (){
Var $ inputs = $ ('input [type = button] ')
. Delay (500)
. Queue (function () {$ (this). hide (). dequeue ();})
. Delay (1500)
. Show ();
//. Show (1 );
});


The above code is hidden and will not be displayed again !! The show method does not specify the animation duration. We can see that dequeue can only execute subsequent methods in the animation queue, but cannot continue executing jquery methods in the non-animation 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.