Data loading can be involved in many projects. Data load can sometimes be 2-3 seconds, in order to give a friendly hint, generally will give a "data load ... "Prompt. Make a prompt box like this today.
First go to the jquery website to see how to write the jquery plugin, and then began to write. Write down a plugin that is slightly optimized for use in the project. The following is the test diagram I wrote this plugin:
This diagram simulates the presentation of the Cue box before the data is loaded, which is written on the page. The blue shading is the mask layer.
(function($) {$.fn.extend ({/** * Open mask and display a text. * @param {string} msg [text displayed] * @param {string} imgsrc [position of picture] * @return {void}*/Openmask:function(msg, imgsrc) {//var loaddiv=$ ("Body"). Find (". _mask_loaddiv"); varloaddiv= This. Find (". _mask_loaddiv"); if(!loaddiv | |!loaddiv[0]) {//Add Mask varloaddiv=$ ("<div class= ' _mask_loaddiv ' style= ' position:absolute; z-index:99999; height:40px; Background: #FFF; border:1px solid #ACE ' ></div> '); if(!IMGSRC) {//Specify a default picture varScripts=document.getelementsbytagname ("Script"); for(vari=0; i<scripts.length; i++){ if(Scripts[i].src.indexof ("Mask")!=-1){ varScriptsrc=scripts[i].src; varUri=scriptsrc.substring (0,scriptsrc.lastindexof ("/")); IMGSRC=uri+ "/images/mask_loading.gif"; } } } varcontentdiv=$ ("<div class= ' _mask_content ' style= ' position:relative;text-align:center; ' >"); varFontsize=12; //Width of loaddiv = width of msg +img width varLoaddiv_width=msg.length*fontsize+16+3; Contentdiv.css ("Width", Loaddiv_width); Loaddiv.css ("Width", Loaddiv_width); if(IMGSRC) {contentdiv.append (" "). Append ("<span style= ' font-size:" +fontsize+ "PX; margin-left:2px; Vertical-align:text-top ' > "+msg+" </span> "); } This. Append (Loaddiv.append (contentdiv)); //$ ("Body"). Append (Loaddiv.append (contentdiv)); /*loaddiv[0].style.top=this[0].offsettop+ (this[0].offsetheight-loaddiv[0].offsetheight)/2; loaddiv[0].style.left=this[0].offsetleft+ (This[0].offsetwidth-loaddiv[0].offsetwidth)/2; loaddiv[0].style.paddingtop= (Loaddiv[0].offsetheight-contentdiv[0].offsetheight)/2; */Loaddiv.css ("Top", This[0].offsettop+ ( This[0].offsetheight-loaddiv[0].offsetheight]/2); Loaddiv.css ("left", This[0].offsetleft+ ( This[0].offsetwidth-loaddiv[0].offsetwidth]/2); Loaddiv.css ("Padding-top", (loaddiv[0].offsetheight-contentdiv[0].offsetheight)/2);} loaddiv.css ("Z-index", 99999). CSS ("Display", "block"); return This; }, Closemask:function(){ //var loaddiv=$ ("Body"). Find (". _mask_loaddiv"); varloaddiv= This. Find (". _mask_loaddiv"); if(Loaddiv) loaddiv.css ("Display", "none"). CSS ("Z-index", 99999); return This; } });}) (jQuery);/*//This is a mask layer information display box, this will be added to the <body> or target element <div class= "_mask_loaddiv" > <div class= "_mask_content" &G T <span>msg</span> </div></div>//This is the target, to show the mask layer on it <di V id= "target" ></div>//only requires the following code: $ ("#target"). Openmask ("Data Loading ... ");//Hide the dialog box, just need: $ (" #target "). Closemask ();*/
Because there are not many CSS involved, it does not follow the principle of HTML, JS, CSS separation, but the CSS are in this JS write.
To test the page code:
varHellodiv; $(function(){ vartbl=$ ("#tableContent"); for(vari=0; i< 16;i++) {tbl.append (' <tr><td width= ' 25% ">hello</td><td width=" 25% ">world</td><td width=" 25% "> JQUERY</TD><TD width= "22%" >mask</td></tr> '); } hellodiv=$ ("#hello"); Hellodiv.openmask (' Data Loading ... ‘); }); functionOpenmask () {Hellodiv.openmask ("Data loading ...." "); } functionClosemask () {Hellodiv.closemask ("Data loading ...." "); } </script> <body> <div id= "Hello" style= "width:300px; height:400px; Background-color: #ACE; " > <table border= "1" width= "100%" id= "tablecontent" > </table> </div& Gt <input value= "Open" type= "button" onclick= "Openmask ();" ><br> <input type= "button" value= "Close" onclick= "Closemask ();" > </body> test.htmlThe key to writing this plugin is to calculate the position of the cue box (top, left), and the ToolTip hierarchy problem (Z-index).
To understand these properties you can look at: CSS location and layout related blogs.
SOURCE See: Http://files.cnblogs.com/f1194361820/jquery-mask.zip
jquery Plugins: Masking + data Loading ... (Features: Cover you want to hide, cover you want to cover)