Javascript pop-up Div (1)

Source: Internet
Author: User

<HTML>
<Head>
<Style>
<! --
Body {font-family:; font-size: 12px; padding: 0px; margin: 0px ;}
. Showwindow: hover {color: # ff0000}

. Win_bg {Background: # CCC; opacity: 0.2; filter: alpha (opacity = 20); position: absolute; left: 0px; top: 0px; width: 100%; Height: 100%; z-index: 998 ;}
. Wintitle {Background: #9 dacbf; Height: 20px; line-Height: 20px}
. Wintitle. title_left {font-weight: bold; color: # FFF; padding-left: 5px; float: Left}
. Wintitle. title_right {float: right}
. Wintitle. title_right A {color: #000; text-Decoration: None}
. Wintitle. title_right A: hover {text-Decoration: underline; color: # ff0000}
. Wincontent {padding: 5px ;}
-->
</Style>
<Script language = "JavaScript">
Function showwindow (){
If (document. getelementbyid ("divwin "))
{
$ ("Divwin"). style. zindex = 999;
$ ("Divwin"). style. Display = "";
}
Else
{
VaR objwin = Document. createelement ("Div ");
Objwin. ID = "divwin ";
Objwin. style. Position = "absolute ";
Objwin. style. width = "400px ";
Objwin. style. Height = "400px ";
Objwin. style. Border = "2px solid # aebbca ";
Objwin. style. Background = "# fff ";
Objwin. style. zindex = 999;
Document. Body. appendchild (objwin );
}

If (document. getelementbyid ("win_bg "))
{
$ ("Win_bg"). style. zindex = 998;
$ ("Win_bg"). style. Display = "";
}
Else
{
VaR obj_bg = Document. createelement ("Div ");
Obj_bg.id = "win_bg ";
Obj_bg.classname = "win_bg ";
Document. Body. appendchild (obj_bg );
}

VaR STR = "";
STR + = '<Div class = "wintitle" onmousedown = "startmove (this, event)" onmouseup = "stopmove (this, event) "> <SPAN class =" title_left "> pop-up window </span> <SPAN class =" title_right "> <a href =" javascript: closewindow () "Title =" Click close this window "> close </a> </span> <br style =" clear: Right "/> </div> '; // Title Bar
STR + = '<Div class = "wincontent"> This is a pop-up window inside the page. The W3C createelement () method and appendchild () method are used. <br/> & nbsp; & nbsp; use Firefox to open the window that can be dragged (ie drag may be faulty) </div> '; // window content
$ ("Divwin"). innerhtml = STR;
}
Function closewindow (){
$ ("Divwin"). style. Display = "NONE ";
$ ("Win_bg"). style. Display = "NONE ";
}
Function $ (o ){
Return document. getelementbyid (O );
}
Function startmove (o, e ){
VaR WB;
If (document. All & E. Button = 1) WB = true;
Else if (E. Button = 0) WB = true;
If (WB)
{
VaR x_pos = parseint (E. clientX-o.parentNode.offsetLeft );
VaR y_pos = parseint (E. clientY-o.parentNode.offsetTop );
If (y_pos <= O. offsetheight)
{
Document.doc umentelement. onmousemove = function (mevent)
{
VaR eevent = (document. All )? Event: mevent;
O. parentnode. style. Left = eevent. clientX-x_pos + "PX ";
O. parentnode. style. Top = eevent. clientY-y_pos + "PX ";
}
}
}
}
Function stopmove (o, e ){
Document.doc umentelement. onmousemove = NULL;
}
</SCRIPT>
</Head>

<Body>
<A class = "showwindow" href = "javascript: showwindow ()"> click here </a> to open the window <br/>
</Body>
</Html>

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.