可拖动DIV提示框

  1. /*
  2.     wanMessageBox弹出框
  3.     msg: 将要显示的信息,如果需要换行以 々 符号隔开
  4.     rowHeight: 每行显示的高度,
  5.     width:消息框的宽度
  6. */
  7. function wanMessageBox(msg, rowHeight, width){
  8.     var pop = window.createPopup();
  9.     var _msg = "";
  10.     var arr = msg.split('々');
  11.     var rowCount = arr.length+1;
  12.     for(var i=0;i<arr.length;i++){
  13.         if(_msg != "") _msg += "<br />  ";
  14.         _msg += arr[i];
  15.     }
  16.     var w = width;
  17.     var h = rowCount * rowHeight + 30;
  18.     /*
  19.       //居中显示
  20.     var l = (document.body.clientWidth - w) / 2;
  21.     var t = (document.body.clientHeight - h) / 2;
  22.     */
  23.     /*
  24.       //显示在右下方
  25.     */
  26.     var l = document.body.scrollWidth - w - 1;
  27.     var t = document.body.clientHeight - h - 1;
  28.     var container = document.createElement("div");
  29.     var items = document.createElement("div");
  30.     items.style.cssText = "z-index:50001; background:#fff; top:" + t + "px; left:" + l + "px; width:" + w + "px; height:" + h + "px; border:4px double #99CCFF;font-size:14px; font-family:宋体;position:absolute;";
  31.     items.onmousedown = mousedown;
  32.     var title = document.createElement("div");
  33.     title.style.cssText = "width:100%; height:26px; cursor:move; line-height:26px; padding-left:5px; background:#fff; border-bottom:1px solid #99CCFF;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#99CCFF, EndColorStr=#EEF7FF);";
  34.     var title_left = document.createElement("div");
  35.     title_left.style.cssText = "float:left;font-weight:bold; color: #113DAE;";
  36.     title_left.innerText = "系统消息";
  37.     var title_right = document.createElement("div");
  38.     title_right.style.cssText = "float:right; font-family:Webdings; font-size:16px; color: white; text-align:center; width:40px; cursor: pointer;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#F0172D, EndColorStr=#ECF5FF);";
  39.     title_right.onclick = _hide;
  40.     title_right.innerText = "r";
  41.     var message = document.createElement("div");
  42.     message.style.cssText = "padding:10px;margin:0; line-height:130%; color:black;";
  43.     message.innerHTML = "  " + _msg;
  44.     title.appendChild(title_left);
  45.     title.appendChild(title_right);
  46.     items.appendChild(title);
  47.     items.appendChild(message);     
  48.     container.appendChild(items);
  49.     
  50.     var bgDiv = document.createElement("div");
  51.     bgDiv.style.cssText = " Z-INDEX: 50000; FILTER: alpha(opacity=50); LEFT: 0px; WIDTH: 100%; POSITION: absolute; TOP: 0px; HEIGHT: 100%; BACKGROUND-COLOR: #BCBCBC; moz-opacity: 0.5; opacity: 0.5";
  52.     bgDiv.onmouseup = function(){return false;}
  53.     bgDiv.onmousemove = function(){return false;}
  54.     bgDiv.onmousedown = function(){return false;}
  55.     bgDiv.onmousedown = function(){return false;}
  56.     bgDiv.ondblclick = function(){return false;}
  57.     bgDiv.onclick = function(){return false;}
  58.     bgDiv.oncontextmenu = function(){return false;}
  59.     bgDiv.onselectstart = function(){return false;}
  60.     document.body.appendChild(container);
  61.     document.body.appendChild(bgDiv);
  62.     _setSelectDisplay("none");
  63.     var x,y,dragObj; 
  64.     function mousedown(){
  65.         var obj = event.srcElement.parentNode;
  66.         dragObj = obj;
  67.         dragObj.onmousemove = mousemove;
  68.         dragObj.onmouseup = mouseup;
  69.         dragObj.setCapture();
  70.         
  71.         oEvent = window.event ? window.event : event;
  72.         x = oEvent.clientX;
  73.         y = oEvent.clientY;
  74.     };
  75.     function mousemove(){
  76.         oEvent = window.event ? window.event : event;
  77.         var _top = oEvent.clientY - y + parseInt(dragObj.style.top);
  78.         var _left = oEvent.clientX - x + parseInt(dragObj.style.left);
  79.         if(_left < 1) _left = 1;
  80.         if(_top < 1) _top = 1;
  81.         var sw = document.body.scrollWidth - dragObj.offsetWidth - 1;
  82.         var sh = document.body.clientHeight - dragObj.offsetHeight - 1;
  83.         if(_left > sw) _left = sw;
  84.         if(_top > sh) _top = sh;
  85.         
  86.         try{
  87.             dragObj.style.top = _top + "px";
  88.             dragObj.style.left = _left + "px";
  89.         }
  90.         catch(e){ }
  91.         x =  oEvent.clientX;
  92.         y =  oEvent.clientY
  93.     };
  94.     function mouseup(){
  95.         dragObj.onmousemove = null;
  96.         dragObj.onmouseup = null;
  97.         dragObj.releaseCapture();
  98.         dragObj = null;
  99.     };
  100.     function _hide(){
  101.         container.style.display = "none";
  102.         bgDiv.style.display = "none";
  103.         _setSelectDisplay("");
  104.     };
  105.     function _setSelectDisplay(dis){
  106.         var selects = document.getElementsByTagName("select");
  107.         for(var i=0;i<selects.length;i++){
  108.             selects[i].style.display = dis;
  109.         }
  110.     };
  111. }

 

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3.  <HEAD>
  4.   <TITLE> New Document </TITLE>
  5.   <META NAME="Generator" CONTENT="EditPlus">
  6.   <META NAME="Author" CONTENT="">
  7.   <META NAME="Keywords" CONTENT="">
  8.   <META NAME="Description" CONTENT="">
  9.   <script type="text/javascript" src="wanMessageBox.js"></script>
  10.   <script type="text/javascript">
  11.     function show(msg){
  12.         var p = new wanMessageBox(msg, 22, 340);
  13.     }
  14.   </script>
  15.  </HEAD>
  16.  <BODY style="margin:0px; padding:0px;">
  17.     <input type="button" onclick="show('北京奥运会北京奥运会北京奥运会北京奥运会々<font color=red><b>恭喜福建龙岩小姑娘夺得蹦床金牌</b></font>々北京奥运会北京奥运会北京奥运会北京奥运会々北京欢迎您!');" value="show">
  18.     <select style="width:100px;"></select>
  19.  </BODY>
  20. </HTML>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值