jquery Add masking layer plug-in

Source: Internet
Author: User

This is the code for the plugin.

1$.fn.extend ({"Showcover": Function () {2     //the translucent layer of the cover layer3     var$div = $ ("<div class= ' cover ' ></div>");4$("Body"). Append ($div);5     //Gets the width and height of the window6     varwidth =$ (window). width ();7     //get the height of the document8     varHeight =$ (window). Height ();9     //Ten$div. CSS ({"width": Width,"Height": Height,"Top":0," Left":0 }); One  A     //Landing Layer -     var$holder = $ ( This); -     //calculate the coordinates of the landing layer the     varx = (width-$holder. Width ())/2; -     vary = ($ (window). Height ()-$holder. Height ())/2; -  -$holder. CSS ({"Top": Y," Left": X,"Display":"Block" }); +  -     // + $ (window). Resize (function () { A $holder. Closecover (); at $holder. Showcover (); -     }) -     return$holder; -},"Closecover": Function () { -$ (window). Unbind ("Resize"); -     if($(". Cover"). length >0) { in         //Remove cover Layer -$(". Cover"). Remove (); to     } +     //Hide Landing Layer -$( This). Hide (); the     return$( This); * } $})
View Code

Code for CSS

1 . Holder2         {3 width:300px;4 height:200px;5background-color:red;6Positionfixed;7 Display:none;8Z-index: -;9         }Ten          One . Cover A         { -background-Color:yellow; -Filter:alpha (opacity= -); theOpacity0.5; -Positionfixed; -              -}
View Code

This is an example

<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">"http://www.w3.org/1999/xhtml">"Mycover.css"Rel="stylesheet"Type="Text/css"/> <script src="Jquery-1.4.1.js"Type="Text/javascript"></script> <script src="Mycover.js"Type="Text/javascript"></script> <script type="Text/javascript">$ (function () {$ ("#wtest"). Showcover (). CSS ("Background-color","Blue"); $(": Button[value=close]"). Click (function () {$ (". Holder"). Closecover (); })        })    </script>"wtest"style="position:fixed; width:300px; height:300px ;">hahaaaaaaaaaa</div></body>View Code

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.