【转】弹出可拖动的DIV层提示窗口

简介: 来源:www.divcss5.com 1 2 3 4 DIVCSS5可拖动DIV提示窗口 5 6 function alertWin(title, msg, w, h) 7 ...

来源:www.divcss5.com

  1 <html>
  2     <head>
  3     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4     <title>DIVCSS5可拖动DIV提示窗口</title>
  5         <script language="javascript">
  6             function alertWin(title, msg, w, h)
  7             {
  8                 var titleheight = "22px"; // 提示窗口标题高度
  9                 var bordercolor = "#666699"; // 提示窗口的边框颜色
 10                 var titlecolor = "#FFFFFF"; // 提示窗口的标题颜色
 11                 var titlebgcolor = "#666699"; // 提示窗口的标题背景色
 12                 var bgcolor = "#FFFFFF"; // 提示内容的背景色
 13             
 14                 var iWidth = document.documentElement.clientWidth;
 15                 var iHeight = document.documentElement.clientHeight;
 16                 var bgObj = document.createElement("div");
 17                 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;";
 18                 document.body.appendChild(bgObj);
 19             
 20                 var msgObj=document.createElement("div");
 21                 msgObj.style.cssText = "position:absolute;font:11px '宋体';top:"+(iHeight-h)/2+"px;left:"+(iWidth-w)/2+"px;width:"+w+"px;height:"+h+"px;text-align:center;border:1px solid "+bordercolor+";background-color:"+bgcolor+";padding:1px;line-height:22px;z-index:102;";
 22                 document.body.appendChild(msgObj);
 23             
 24                 var table = document.createElement("table"); //www.divcss5.com divcss5
 25                 msgObj.appendChild(table);
 26                 table.style.cssText = "margin:0px;border:0px;padding:0px;";
 27                 table.cellSpacing = 0;
 28                 var tr = table.insertRow(-1);
 29                 var titleBar = tr.insertCell(-1);
 30                 titleBar.style.cssText = "width:100%;height:"+titleheight+"px;text-align:left;padding:3px;margin:0px;font:bold 13px '宋体';color:"+titlecolor+";border:1px solid " + bordercolor + ";cursor:move;background-color:" + titlebgcolor;
 31                 titleBar.style.paddingLeft = "10px";
 32                 titleBar.innerHTML = title;
 33                 var moveX = 0;
 34                 var moveY = 0;
 35                 var moveTop = 0;
 36                 var moveLeft = 0;
 37                 var moveable = false;
 38                 var docMouseMoveEvent = document.onmousemove; //www.divcss5.com divcss5
 39                 var docMouseUpEvent = document.onmouseup;
 40                 titleBar.onmousedown = function() 
 41                 {
 42                     var evt = getEvent();
 43                     moveable = true;
 44                     moveX = evt.clientX;
 45                     moveY = evt.clientY;
 46                     moveTop = parseInt(msgObj.style.top);
 47                     moveLeft = parseInt(msgObj.style.left);
 48                 
 49                     document.onmousemove = function() 
 50                     {
 51                         if (moveable) 
 52                         {
 53                             var evt = getEvent();
 54                             var x = moveLeft + evt.clientX - moveX; //www.divcss5.com divcss5
 55                             var y = moveTop + evt.clientY - moveY;
 56                             if ( x > 0 &&( x + w < iWidth) && y > 0 && (y + h < iHeight) ) 
 57                             {
 58                                 msgObj.style.left = x + "px";
 59                                 msgObj.style.top = y + "px";
 60                             }
 61                         }
 62                     };
 63                     document.onmouseup = function () 
 64                     {
 65                         if (moveable) 
 66                         {
 67                             document.onmousemove = docMouseMoveEvent; //www.divcss5.com divcss5
 68                             document.onmouseup = docMouseUpEvent;
 69                             moveable = false;
 70                             moveX = 0;
 71                             moveY = 0;
 72                             moveTop = 0;
 73                             moveLeft = 0;
 74                         }
 75                     };
 76                 }
 77             
 78                 var closeBtn = tr.insertCell(-1);
 79                 closeBtn.style.cssText = "cursor:pointer; padding:2px;background-color:" + titlebgcolor;
 80                 closeBtn.innerHTML = "<span style='font-size:15pt; color:"+titlecolor+";'>×</span>";
 81                 closeBtn.onclick = function()
 82                 {
 83                     document.body.removeChild(bgObj);
 84                     document.body.removeChild(msgObj);
 85                 }
 86                 var msgBox = table.insertRow(-1).insertCell(-1);
 87                 msgBox.style.cssText = "font:10pt '宋体';";
 88                 msgBox.colSpan = 2;
 89                 msgBox.innerHTML = msg;
 90             
 91                 // 获得事件Event对象,用于兼容IE和FireFox
 92                 function getEvent() 
 93                 {
 94                     return window.event || arguments.callee.caller.arguments[0];
 95                 }
 96             }
 97         </script>
 98     </head>
 99     <body>
100         <input type="button" value="DIVCSS5" onclick="alertWin('标题','测试内容<a href=\'http://www.divcss5.com\'>CSS</a>内容400是宽度200是高度',400,200);" />
101         <!-- asp.net里面上述按钮用html的button控件即可。 -->
102     </body>
103 </html>

 

相关文章
|
5月前
|
小程序 前端开发 JavaScript
小程序点击按钮出现和隐藏遮罩层
小程序点击按钮出现和隐藏遮罩层
155 0
|
5月前
鼠标移到到div上,div放大
鼠标移到到div上,div放大
|
5月前
div层定位在网页右下角
div层定位在网页右下角
22 0
|
5月前
layer 父弹出框上弹出子弹框窗体大小问题
layer 父弹出框上弹出子弹框窗体大小问题
|
5月前
解决uviewui向下展开菜单u-dropdown组件收起样式层叠问题
解决uviewui向下展开菜单u-dropdown组件收起样式层叠问题
|
9月前
layui列表页滚动时弹出窗无法居中的解决方案
layui列表页滚动时弹出窗无法居中的解决方案
81 0
|
前端开发 Android开发
如何操作SAP UI5应用Footer区域工具栏按钮的背景颜色
如何操作SAP UI5应用Footer区域工具栏按钮的背景颜色
125 0
如何操作SAP UI5应用Footer区域工具栏按钮的背景颜色
|
Web App开发 前端开发 JavaScript
|
JavaScript 前端开发