JQUERY pop-up mode DIV

Source: Internet
Author: User

The pop-up DIV is jointly controlled by JQUERY + CSS. The JQUERY pop-up window displays and displays the effect of the CSS control layer.

Page code:


[Html]
<% @ Page language = "java" contentType = "text/html; charset = UTF-8"
PageEncoding = "UTF-8" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Script type = "text/javascript" src = "scripts/jquery-1.8.3.js"> </script>
<Script type = "text/javascript" src = "script/pop. js"> </script>
<Link type = 'text/css 'rel = 'stylesheet' href = 'style/pop.css '/>
<Title> Insert title here </title>
</Head>
<Body>
 
<Div id = 'pop-div 'style = "width: 300px" class = "pop-box">
<H4 class = "pop-boxh4"> title Position <Div class = "pop-box-body">
<P> pop-up content </p>
</Div>
<Div id = 'buttonpanel' style = "text-align: right"
Style = "text-align: right">
<Input type = "button" value = "Close" id = "btn1"
Onclick = "hideDiv ('pop-div ');"/>
</Div>
</Div>
<Input type = "button" value = "select" onclick = "popupDiv ('pop-div ')"
Style = "cursor: pointer;">
</Body>
</Html>

<% @ Page language = "java" contentType = "text/html; charset = UTF-8"
PageEncoding = "UTF-8" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Script type = "text/javascript" src = "scripts/jquery-1.8.3.js"> </script>
<Script type = "text/javascript" src = "script/pop. js"> </script>
<Link type = 'text/css 'rel = 'stylesheet' href = 'style/pop.css '/>
<Title> Insert title here </title>
</Head>
<Body>

<Div id = 'pop-div 'style = "width: 300px" class = "pop-box">
<H4 class = "pop-boxh4"> title Position <Div class = "pop-box-body">
<P> pop-up content </p>
</Div>
<Div id = 'buttonpanel' style = "text-align: right"
Style = "text-align: right">
<Input type = "button" value = "Close" id = "btn1"
Onclick = "hideDiv ('pop-div ');"/>
</Div>
</Div>
<Input type = "button" value = "select" onclick = "popupDiv ('pop-div ')"
Style = "cursor: pointer;">
</Body>
</Html>
JS Code


[Javascript]
Function popupDiv (div_id ){
// Obtain the input DIV
Var $ div_obj = $ ("#" + div_id );
// Computer screen height
Var rows wwidth = $ (window). width ();
// Computer screen Length
Var success wheight = $ (window). height ();
// Obtain the height of the input DIV
Var popupHeight = $ div_obj.height ();
// Get the length of the input DIV
Var popupWidth = $ div_obj.width ();
//// Add and display the Mask Layer
$ ("<Div id = 'bg '> </div>"). width (wxwwidth * 0.99)
. Height (optional wheight * 0.99). click (function (){
HideDiv (div_id );
}). AppendTo ("body"). fadeIn (200 );
// Display the pop-up DIV
$Div_obj.css ({
"Position": "absloute"
}). Animate ({
Left: descriwwidth/2-popupWidth/2,
Top: Always wheight/2-popupHeight/2,
Opacity: "show"
}, "Slow ");

}
/* Hide the pop-up DIV */
Function hideDiv (div_id ){
$ ("# Bg"). remove ();
$ ("#" + Div_id). animate ({
Left: 0,
Top: 0,
Opacity: "hide"
}, "Slow ");
}

Function popupDiv (div_id ){
// Obtain the input DIV
Var $ div_obj = $ ("#" + div_id );
// Computer screen height
Var rows wwidth = $ (window). width ();
// Computer screen Length
Var success wheight = $ (window). height ();
// Obtain the height of the input DIV
Var popupHeight = $ div_obj.height ();
// Get the length of the input DIV
Var popupWidth = $ div_obj.width ();
//// Add and display the Mask Layer
$ ("<Div id = 'bg '> </div>"). width (wxwwidth * 0.99)
. Height (optional wheight * 0.99). click (function (){
HideDiv (div_id );
}). AppendTo ("body"). fadeIn (200 );
// Display the pop-up DIV
$Div_obj.css ({
"Position": "absloute"
}). Animate ({
Left: descriwwidth/2-popupWidth/2,
Top: Always wheight/2-popupHeight/2,
Opacity: "show"
}, "Slow ");
 
}
/* Hide the pop-up DIV */
Function hideDiv (div_id ){
$ ("# Bg"). remove ();
$ ("#" + Div_id). animate ({
Left: 0,
Top: 0,
Opacity: "hide"
}, "Slow ");
}

CSS code


[Css]
@ CHARSET "UTF-8 ";
. Pop-box-body {
Clear: both;
Margin: 4px;
Padding: 2px;
}
 
. Pop-boxh4 {
Color: # FFF;
Cursor: default;
Height: 18px;
Font-size: 14px;
Font-weight: bold;
Text-align: left;
Padding-left: 8px;
Padding-top: 4px;
Padding-bottom: 2px;
Background: blue;
}
 
. Pop-box {
/* After the pop-up window, the pop-up DIV uses this CSS to ensure that it is placed at the top layer.
Z-index controls the z-axis coordinates. The greater the value, the closer it is to the user.
*/
Z-index: 9999999;/* This value must be large enough to display on the top */
Margin-bottom: 3px;
Display: none;
Position: absolute;
Background: gray;
Border: solid1px # 6e8bde;
}
 
# Bg {
Width: 100%;
Height: 100%;
Position: absolute;
Top: 0;
Left: 0;
/* In the pop-up window, add a mask layer. Use this CSS to place the layer between the pop-up DIV and the page layer.
Z-index controls the z-axis coordinates. The greater the value, the closer it is to the user.
*/
Z-index: 5;
Background: white;
}

@ CHARSET "UTF-8 ";
. Pop-box-body {
Clear: both;
Margin: 4px;
Padding: 2px;
}

. Pop-boxh4 {
Color: # FFF;
Cursor: default;
Height: 18px;
Font-size: 14px;
Font-weight: bold;
Text-align: left;
Padding-left: 8px;
Padding-top: 4px;
Padding-bottom: 2px;
Background: blue;
}

. Pop-box {
/* After the pop-up window, the pop-up DIV uses this CSS to ensure that it is placed at the top layer.
Z-index controls the z-axis coordinates. The greater the value, the closer it is to the user.
*/
Z-index: 9999999;/* This value must be large enough to display on the top */
Margin-bottom: 3px;
Display: none;
Position: absolute;
Background: gray;
Border: solid1px # 6e8bde;
}

# Bg {
Width: 100%;
Height: 100%;
Position: absolute;
Top: 0;
Left: 0;
/* In the pop-up window, add a mask layer. Use this CSS to place the layer between the pop-up DIV and the page layer.
Z-index controls the z-axis coordinates. The greater the value, the closer it is to the user.
*/
Z-index: 5;
Background: white;
}

 

 

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.