Html:
<meta charset= "Utf-8" >
<title>jquery pop-up layer </title>
<script type= "Text/javascript" src= ". /js/jquery/jquery-1.12.4.min.js "></script>
<body>
<div class= "Header" >
<a id= "Loginlink" href= "#" > Login </a>
<a id= "Regelink" href= "#" > Registration </a>
</div>
<!--the pop-up layer matte-
<div id= "Layer-mask" class= "Layer-mask" ></div>
<!--pop-up layers form-
<div id= "Layer-pop" class= "Layer-pop" >
<!--pop-up layer off button--
<div id= "Layer-close" class= "Layer-close" >x</div>
<!--pop-up layer content area--
<div id= "layer-content" class= "Layer-content" >
</div>
</div>
<!--login Form-
<div id= "loginhtml" style= "Display:none;" >
<!--login Form-
<div class= "Login" >
<div class= "Item" >
<label> Account </label>
<input id= "username" class= "input" name= "username" type= "text"/>
<p class= "Error-msg" ></p>
</div>
<div class= "Item" >
<label> Password </label>
<input id= "password" class= "input" name= "password" type= "password"/>
</div>
<div class= "Item" >
<label> </label>
<input id= "loginsubmitbtn" type= "Submit" class= "submit" value= "filled in"/>
</div>
</div>
</div>
<!--Registration Form-
<div id= "regehtml" style= "Display:none;" >
<!--Registration Form-
<div class= "Login" >
<div class= "Item" >
<label> Account </label>
<input id= "username" class= "input" name= "username" type= "text"/>
<p class= "Error-msg" ></p>
</div>
<div class= "Item" >
<label> Password </label>
<input id= "password" class= "input" name= "password" type= "password"/>
</div>
<div class= "Item" >
<label> Duplicate Password </label>
<input id= "Repassword" class= "input" name= "Repassword" type= "password"/>
</div>
<div class= "Item" >
<label> </label>
<input id= "regesubmitbtn" type= "Submit" class= "submit" value= "filled in"/>
</div>
</div>
</div>
</body>
Css:
*{margin:0;padding:0;}
Body
{
Text-align:center;
line-height:30px;
}
/* Popup Layer Mask */
. layer-mask
{
Display:none;
z-index:99999;
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
Background: #000;
opacity:0.5;
}
/* Popup Layer form */
. layer-pop
{
Display:none;
z-index:100000;
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
Margin:auto;
width:400px;
height:300px;
Background: #fff;
}
/* Popup Layer Close button */
. layer-close
{
Float:right;
width:24px;
height:24px;
BORDER:3PX solid #fff;
Text-align:center;
line-height:24px;
border-radius:50%;
Background: #eee;
Margin-right: -12px;
margin-top:-12px;
}
. layer-close:hover
{
Cursor:pointer;
Background: #ccc;
Color: #fff;
}
/* Login */
. Login
{
}
. Login H4
{
font-size:20px;
line-height:50px;
}
. Login Label
{
margin-right:5px;
Color: #888;
Display:inline-block;
width:60px;
Text-align:right;
}
. Login. Input
{
border:1px solid #ccc;
border-radius:3px;
padding:10px 5px;
width:250px;
}
. Login. Item
{
margin:20px Auto;
}
. Login. Submit
{
Background: #e40;
border:1px solid #e40;
border-radius:5px;
padding:10px 5px;
width:250px;
Color: #fff;
}
. Login. error-msg
{
Color: #e40;
}
/* Top */
. Header
{
height:80px;
line-height:80px;
Text-align:right;
Margin:0 20px;
Overflow:hidden;
}
. Header A
{
Color: #666;
Text-decoration:none;
margin-left:20px;
}
Js:
$ (document). Ready (function ($) {
Login Link Event
$ ("#loginLink"). Click (function () {
Get Login Form Code
var loginhtml = $ ("#loginHtml"). html ();
Showlayer (Loginhtml,500,300,closecallback);
Login form Check
$ ("#loginSubmitBtn"). Click (function () {
var username = $ ("Input[name= ' username ')"). Val ();
var password = $ ("input[name= ' password ')"). Val ();
if (username = = = ' Imooc ' && password = = = ' Imooc ') {
Alert ("Login successful");
}else{
$ (". Error-msg"). HTML ("Error in Account or password entry");
}
});
});
Registering Link Events
$ ("#regeLink"). Click (function () {
Get registration Form Code
var regehtml = $ ("#regeHtml"). html ();
Showlayer (Regehtml,500,350,closecallback);
Registration Form Check
$ ("#regeSubmitBtn"). Click (function () {
var username = $ ("Input[name= ' username ')"). Val ();
var password = $ ("input[name= ' password ')"). Val ();
var Repassword = $ ("input[name= ' Repassword ')"). Val ();
if (username = = = ' Imooc ' && password = = = ' Imooc ' && repassword = = password) {
Alert ("Registered success");
}else{
$ (". Error-msg"). HTML ("Error in Account or password entry");
}
});
});
Popup Layer Shutdown callback function
function Closecallback () {
$ (". Error-msg"). HTML ("");
}
Show pop-up layer
function Showlayer (html,width,height,closecallback) {
Show Popup layer Matte
$ ("#layer-mask"). Show ();
Show Popup Layer Form
$ ("#layer-pop"). Show ();
Set the popup layer form style
$ ("#layer-pop"). CSS ({
Width:width,
Height:height
});
Populate the popup layer form contents
$ ("#layer-content"). HTML (HTML);
Popup Layer Close button bind event
$ ("#layer-close"). Click (function () {
Pop-up layer off
Hidelayer ();
Closed callback function
Closecallback ();
});
}
Hide pop-up layers
function Hidelayer () {
Pop-up layer off
$ ("#layer-mask"). Hide ();
$ ("#layer-pop"). Hide ();
}
});
jquery-Pop-up layer