A JQuery-Based mask Layer (mask)

Source: Internet
Author: User

If ExtJs is used, you may know that many UI elements are integrated in ExtJs, which makes it easy for us to use. There are two methods, mask () and unmask (). These two methods add a mask layer and a notification message implementation on the specified element to improve the customer experience. Recently, when I was working on a project, I found that sometimes I need to introduce a relatively "large" Extjs to use these two methods, which is a bit uneconomical, therefore, jquery is used to implement a simple mask and unmask method to achieve this effect. As we all know, jquery is an excellent javascript framework, which is not only small but also easy to use. Now I gradually replace all or all the Code implemented by Extjs IN THE SYSTEM WITH Jquery for implementation. Well, I don't know much about it. On my code, this Code is based on the documentMask implemented by a friend on the Internet. It makes use more flexible and convenient.

Copy to ClipboardReference: [www.bkjia.com] (function (){
$. Extend ($. fn ,{
Mask: function (msg, maskDivClass ){
This. unmask ();
// Parameters
Var op = {
Opacity: 0.8,
Z: 10000,
Bgcolor: '# ccc'
};
Var original = $ (document. body );
Var position = {top: 0, left: 0 };
If (this [0] & this [0]! Invalid parameter Doc ument ){
Original = this;
Position = original. position ();
}
// Create a Mask layer and append it to the object
Var maskDiv =$ ('<div class = "maskdivgen"> </div> ');
MaskDiv. appendTo (original );
Var maskWidth = original. outerWidth ();
If (! MaskWidth ){
MaskWidth = original. width ();
}
Var maskHeight = original. outerHeight ();
If (! MaskHeight ){
MaskHeight = original. height ();
}
MaskDiv.css ({
Position: 'absolute ',
Top: position. top,
Left: position. left,
'Z-Index': op. z,
Width: maskWidth,
Height: maskHeight,
'Background-color': op. bgcolor,
Opacity: 0
});
If (maskDivClass ){
MaskDiv. addClass (maskDivClass );
}
If (msg ){
Var msgDiv = $ ('<div style = "position: absolute; border: # 6593cf 1px solid; padding: 2px; background: # ccca "> <div style =" line-height: 24px; border: # a3bad9 1px solid; background: white; padding: 2px 10px 2px 10px "> '+ msg +' </div> ');
MsgDiv. appendTo (maskDiv );
Var widthspace = (maskDiv. width ()-msgDiv. width ());
Var heightspace = (maskDiv. height ()-msgDiv. height ());
MsgDiv.css ({
Cursor: 'wait ',
Top :( heightspace/2-2 ),
Left :( widthspace/2-2)
});
}
MaskDiv. fadeIn ('quick', function (){
// Fade-in and fade-out effect bkjia.com
$ (This). fadeTo ('low', op. opacity );
})
Return maskDiv;
},
Unmask: function (){
Var original = $ (document. body );
If (this [0] & this [0]! Invalid parameter Doc ument ){
Original = $ (this [0]);
}
Original. find ("> div. maskdivgen"). fadeOut ('low', 0, function (){
$ (This). remove ();
});
}
});
})();

The following is the sample code:

<Html> 

Tip: the code can be modified before running!

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.