JS Popup div window can be moved to close

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >


<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> Untitled Document </title>
<script language= "JavaScript" >
function Alertwin (str) {
var MSGW, MSGH, bordercolor;
MSGW = 300;//The width of the hint window
MSGH = 100;//The height of the prompt window
Titleheight = 25//Hint window caption height
bordercolor = "#A480B2";//Border color of the hint window
Titlecolor = "#A480B2";//title Color of the hint window

Pay attention to the adjustment of width and height according to your own needs
var iwidth = document.documentElement.clientWidth;
var iheight = document.documentElement.clientHeight;
Mask Layer
var bgobj = document.createelement ("div");
Bgobj.setattribute ("id", "bgobj");//Set ID
BgObj.style.cssText = "Position:absolute;left:0px;top:0px;width:" +iwidth+ "Px;height:" +math.max ( Document.body.clientHeight, iheight) + "Px;filter:alpha (opacity=30); Opacity:0.3;background-color: #000000; z-index : 101; ";
Document.body.appendChild (Bgobj);

//Popup
var msgobj=document.createelement ("div"),
Msgobj.setattribute ("id", "msgdiv");//Can be used bgobj.id= " The Msgdiv "method is to specify the property value for the div
Msgobj.setattribute (" Align "," center "),//For the align assignment of the div
MsgObj.style.background =" White ";///The background color is
MsgObj.style.border =" 1px solid "+ bordercolor;//border property, color is assigned above
MsgObj.style.position =" Absolute ";//absolute positioning
MsgObj.style.left = (IWIDTH-MSGW)/2;//starting from the left
MsgObj.style.top = (IHEIGHT-MSGH)/2;//from the upper starting position
MsgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, Sans-serif";//font properties
MsgObj.style.width = MSGW + "PX";//the width of the hint box (defined above)
MsgObj.style.height = msgh + "px";//the height of the cue box (defined above)
MsgObj.style.textAlign = "center";// Text Position property, centered.
MsgObj.style.lineHeight = "25px";//Line spacing
MsgObj.style.zIndex = "102";//z-axis position of the layer
Document.body.appendChild ( Msgobj);

Pop-up window title
var title = document.createelement ("div");//Create a Caption object
Title.setattribute ("id", "msgtitle");//Add ID to Title object
Title.style.margin = "0";//Floating
title.style.padding = "3px";//Floating
Title.style.background = titlecolor;//background color
Title.style.filter = "Progid:DXImageTransform.Microsoft.Alpha (startx=20, starty=20, finishx=100, finishy=100,style= 1,OPACITY=75,FINISHOPACITY=100); ";
title.style.opacity = "0.75";//Transparent
Title.style.border= "1px solid" + bordercolor;//border
Title.style.height = "25px";//height
Title.style.font = "12px Verdana, Geneva, Arial, Helvetica, Sans-serif";//font properties
Title.style.color = "red";//Text color
Title.style.cursor = "move";//Mouse style
Title.innerhtml= "<table border= ' 0 ' width= ' 100% ' ><tr><td align= ' left ' >2222</td><td align =\ "right\" ><a href= ' # ' onclick= ' Closediv () ' >x</a></td></tr></table> ';

The settings window can be moved

var MoveX = 0;
var movey = 0;
var movetop = 0;
var moveLeft = 0;
var moveable = false;
var docmousemoveevent = Document.onmousemove;
var docmouseupevent = Document.onmouseup;
Title.onmousedown = function () {
var evt = getEvent ();
moveable = true;
MoveX = Evt.clientx;
Movey = Evt.clienty;
Movetop = parseint (msgObj.style.top);
MoveLeft = parseint (msgObj.style.left);
Document.onmousemove = function () {
if (moveable) {
var evt = getEvent ();
var x = moveLeft + Evt.clientx-movex;
var y = movetop + Evt.clienty-movey;
if (x > 0 && (x + MSGW < iwidth) && y > 0 && (y + msgh < iheight)) {
MsgObj.style.left = x + "px";
MsgObj.style.top = y + "px";
}
}
};
Document.onmouseup = function () {
if (moveable) {
Document.onmousemove = docmousemoveevent;
Document.onmouseup = docmouseupevent;
moveable = false;
MoveX = 0;
Movey = 0;
movetop = 0;
MoveLeft = 0;
}
};
}
Get event object for compatibility with IE and Firefox
function GetEvent () {
return Window.event | | Arguments.callee.caller.arguments[0];
}

Msgobj.appendchild (title);//Add a caption to the Cue box
var txt = document.createelement ("P");
Txt.style.margin = "1em 0";//Text floating
Txt.setattribute ("id", "msgtxt");//Add id attribute for P property
txt.innerhtml = str;//assigns the passed in value to the P attribute
Msgobj.appendchild (TXT);//Add the P attribute to the hint box
}

Add off feature
function Closediv () {
var msgtitelobject = document.getElementById ("Msgdiv");
Document.body.removeChild (Msgtitelobject);
var bgobj = document.getElementById ("Bgobj");
Document.body.removeChild (Bgobj);

}

</script>

<body>
<input type= "button" value= "xx" onclick= "Alertwin (' message subject ');"/>
</body>

JS Popup div window can be moved to close

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.