JS page delay execution methods (sorting)

Source: Internet
Author: User

Generally, some methods are executed at the JS page latency. You can use the following methods
JQuery. delay () method Overview
Http://shawphy.com/2010/11/jquery-delay.html
Queue and dequeue usage in jQuery
Http://www.jb51.net/article/25481.htm
Window. setTimeout
Http://www.jb51.net/article/20741.htm
Here are some examples I have used.
Copy codeThe Code is as follows:
// Delayed query: Upload a btn ID for query, and bind it to the FORM near it. When the control in the FORM is triggered or entered, the query button will be clicked after 500 milliseconds.
Var timeout;
Function searchTrigerInit (btnId ){
Var $ form = $ ("#" + btnId). closest ("form ");
$ Form. find ("input"). not (". search_onblur"). keyup (function (){
SearchTriger (btnId );
});
$ Form. find ("input. search_onblur"). blur (function (){
SearchTriger (btnId );
});
$ Form. find ("input [type = checkbox]"). change (function (){
SearchTriger (btnId );
});
$ Form. find ("select"). change (function (){
SearchTriger (btnId );
});
}
Function searchTriger (btnId ){
If (timeout! = Null ){
ClearTimeout (timeout );
}
Timeout = setTimeout ("searchBtnClick ('" + btnId + "')", 500 );
}
Function searchBtnClick (btnId ){
$ ("#" + BtnId). click ();
}

Defines the mask layer, which is closed after one minute
Copy codeThe Code is as follows:
Var hideTimeout;
Function showLayerMask (){
$ LayerMask = $ (". layerMask ");
If ($ layerMask. length = 0 ){
Var div = "";
Var width = document. body. clientWidth;
Var Height = document. body. scrollHeight;
Var img = " ";
Div + = "<div class = 'layermask' style = 'width: 100%; height:" + Height + "px; '> ";
Div + = img;
Div + = "</div> ";
Var $ body = $ ("body ");
$ Body. prepend (div );
}
$ LayerMask. show ();
// Cancel in 1 minute
HideTimeout = setTimeout (hideLayerMask, 60000 );
}
Function hideLayerMask (){
If (hideTimeout! = Null ){
ClearTimeout (hideTimeout );
}
$ LayerMask = $ (". layerMask ");
$ LayerMask. hide ();
}

Countdown
Copy codeThe Code is as follows:
Var emailTime = 30;
Function nextCanDo (){
$ ("# MailValidateCodeBtn"). val (emailTime + "second ");
EmailTime-= 1;
If (emailTime = 0 ){
$ ("# MailValidateCodeBtn"). val ("retrieve verification code again ");
$ ("# MailValidateCodeBtn"). attr ("disabled", false );
EmailTime = 30;
} Else {
SetTimeout ("nextCanDo ()", 1000 );
}
}

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.