Js implementation: drag the alert div simulation Layer

Source: Internet
Author: User

<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> Can you drag me? </Title>
<Script language = "javascript">
<! --
Function cry (){
Alert ("can you drag me? ")
}
// -->
</Script>
<Script language = "javascript">
<! --
Window. alert = function (txt)
{
Var shield = document. createElement ("DIV ");
Shield. id = "shield ";
Shield. style. position = "absolute ";
Shield. style. left = "0px ";
Shield. style. top = "0px ";
Shield. style. width = "100% ";
Shield. style. height = "100% ";
// Shield. style. height = document. body. scrollHeight + "px ";
Shield. style. background = "#000 ";
Shield. style. textAlign = "center ";
Shield. style. zIndex = "10000 ";
Shield. style. filter = "alpha (opacity = 0 )";
Var alertFram = document. createElement ("DIV ");
AlertFram. id = "alertFram ";
AlertFram. style. position = "absolute ";
// The negative boundary Center Method, relative to the top of the shield layer

// AlertFram. style. left = "50% ";
// AlertFram. style. top = "50% ";
// AlertFram. style. marginLeft = "-125px ";
// AlertFram. style. marginTop = "-75px ";

// The negative boundary Center Method, relative to the bottom of the shield layer
AlertFram. style. right = "50% ";
AlertFram. style. bottom = "50% ";
AlertFram. style. marginRight = "-125px ";
AlertFram. style. marginBottom = "-75px ";

AlertFram. style. width = "250px ";
AlertFram. style. height = "150px ";
AlertFram. style. background = "#000 ";
AlertFram. style. textAlign = "center ";
AlertFram. style. lineHeight = "150px ";
AlertFram. style. zIndex = "10002 ";
StrHtml = "<ul style =" list-style: none; margin: 0px; padding: 0px; width: 100% "> ";
StrHtml + = "<li onmousedown =" oMove (parentNode. parentNode); "title =" "style =" cursor: move; background: # 002F9C; text-align: left; padding-left: 5px; font-size: 14px; font-weight: bold; color: # FFFFFF; height: 25px; line-height: 25px; border-left: 1px solid # FFFFFF; border-top: 1px solid # FFFFFF; border-right: 1px solid # FFFFFF; "> [prompt...] </Li> ";
StrHtml + = "<li style =" background: # 5A7EDC; text-align: center; font-size: 12px; color: # FFFFFF; height: 120px; line-height: 120px; border-left: 1px solid # FFFFFF; border-right: 1px solid # FFFFFF; ">" + txt + "</li> ";
StrHtml + = "<li style =" background: # 002F9C; text-align: center; font-weight: bold; height: 25px; line-height: 25px; border-left: 1px solid # FFFFFF; border-bottom: 1px solid # FFFFFF; border-right: 1px solid # FFFFFF; "> <input type = button value = confirm onclick =" remove () "> </li> ";
StrHtml + = "</ul> ";
AlertFram. innerHTML = strHtml;
Document. body. appendChild (alertFram );
Document. body. appendChild (shield );
Var c = 0;
This. doAlpha = function (){
If (c ++> 50) {clearInterval (ad); return 0 ;}
Shield. style. filter = "alpha (opacity =" + c + ");";
}
This. remove = function (){
AlertFram. innerHTML = "";
Shield. style. filter = "";
Shield. id = "";
Shield. style. position = "";
Shield. style. left = "";
Shield. style. top = "";
Shield. style. width = "";
Shield. style. height = "";
Shield. style. background = "";
Shield. style. textAlign = "";
Shield. style. zIndex = "";
Shield. style. filter = "";
AlertFram. id = "";
AlertFram. style. position = "";
AlertFram. style. left = "";
AlertFram. style. top = "";
AlertFram. style. marginLeft = "";
AlertFram. style. marginTop = "";
AlertFram. style. width = "";
AlertFram. style. height = "";
AlertFram. style. background = "";
AlertFram. style. textAlign = "";
AlertFram. style. lineHeight = "";
AlertFram. style. zIndex = "";
}
Var ad = setInterval ("doAlpha ()", 10 );
AlertFram. focus ();
Document. body. onselectstart = function () {return false ;};
}
Function oMove (obj ){
Var otop, oleft;
Otop = event. y-obj. offsetTop;
Oleft = event. x-obj. offsetLeft;
Obj. setCapture ();
Obj. = function ()
{
Obj. style. left = event. x-oleft;
Obj. style. top = event. y-otop;
}
Obj. = function ()
{
Obj. = null;
Obj. style. filter = null;
Obj. releaseCapture ();
}
}
// -->
</Script>
</Head>
<Body style = "margin: 0;">
<Input type = submit name = "cry" value = "Click ^_^" style = "width: 110px; height: 30px" onClick = "cry () "> </input>
</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.