jquery Plugins: Masking + data Loading ... (Features: Cover you want to hide, cover you want to cover)

Source: Internet
Author: User

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 ({/** *) opens the matte and displays a paragraph of text.        * @param {string} msg [text displayed] * @param {string} imgsrc [Picture location] * @return {void} */            Openmask:function (msg, IMGSRC) {//var loaddiv=$ ("Body"). Find (". _mask_loaddiv");            var loaddiv=this.find (". _mask_loaddiv"); if (!loaddiv | |!loaddiv[0]) {//Add Mask var loaddiv=$ ("<div class= ' _mask_loaddiv ' style= ' position:a Bsolute; z-index:99999; height:40px; Background: #FFF;                                border:1px solid #ACE ' ></div> ');                    if (!IMGSRC) {//specify default picture var scripts=document.getelementsbytagname ("script");                            for (var i=0; i<scripts.length; i++) {if (Scripts[i].src.indexof ("Mask")!=-1) {                            var scriptsrc=scripts[i].src;                            var uri=scriptsrc.substring (0,scriptsrc.lastindexof ("/")); Imgsrc=uri+ "/images/mask_loading.gif"; }}} var contentdiv=$ ("<div class= ' _mask_content ' style= ' Position:rel                ative;text-align:center; ' > ');                var fontsize=12;                The width of the Loaddiv = the width of the msg +img the width of var loaddiv_width=msg.length*fontsize+16+3;                Contentdiv.css ("width", loaddiv_width);                Loaddiv.css ("width", loaddiv_width); if (IMGSRC) {contentdiv.append (" "+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");            var loaddiv=this.find (". _mask_loaddiv");            if (loaddiv) loaddiv.css ("Display", "none"). CSS ("Z-index",-99999);        return this; }    });})   (jQuery);/*//This is the overlay information box, which is added to the <body> or target element <div class= "_mask_loaddiv" > <div class= "_mask_content" >  <span>msg</span> </ div></div>//This is the target, to show the mask layer on it <div 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:

The 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)

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.