`
javatoyou
  • 浏览: 1016985 次
  • 性别: Icon_minigender_2
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

JS模拟ALERT半透明背景,仿关机效果

 
阅读更多
  1. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <htmlxmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title></title>
  5. <style>
  6. html,body{font-size:12px;margin:0px;height:100%;}
  7. .mesWindow{border:#6661pxsolid;background:#fff;}
  8. .mesWindowTop{border-bottom:#eee1pxsolid;margin-left:4px;padding:3px;font-weight:bold;text-align:left;font-size:12px;}
  9. .mesWindowContent{margin:4px;font-size:12px;}
  10. .mesWindow.close{height:15px;width:28px;border:none;cursor:pointer;text-decoration:underline;background:#fff}
  11. </style>
  12. <script>
  13. varisIe=(document.all)?true:false;
  14. //设置select的可见状态
  15. functionsetSelectState(state)
  16. {
  17. varobjl=document.getElementsByTagName('select');
  18. for(vari=0;i<objl.length;i++)
  19. {
  20. objl[i].style.visibility=state;
  21. }
  22. }
  23. functionmousePosition(ev)
  24. {
  25. if(ev.pageX||ev.pageY)
  26. {
  27. return{x:ev.pageX,y:ev.pageY};
  28. }
  29. return{
  30. x:ev.clientX+document.body.scrollLeft-document.body.clientLeft,y:ev.clientY+document.body.scrollTop-document.body.clientTop
  31. };
  32. }
  33. //弹出方法
  34. functionshowMessageBox(wTitle,content,pos,wWidth)
  35. {
  36. closeWindow();
  37. varbWidth=parseInt(document.documentElement.scrollWidth);
  38. varbHeight=parseInt(document.documentElement.scrollHeight);
  39. if(isIe){
  40. setSelectState('hidden');}
  41. varback=document.createElement("div");
  42. back.id="back";
  43. varstyleStr="top:0px;left:0px;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;";
  44. styleStr+=(isIe)?"filter:alpha(opacity=40);":"opacity:0.40;";
  45. back.style.cssText=styleStr;
  46. document.body.appendChild(back);
  47. varmesW=document.createElement("div");
  48. mesW.id="mesWindow";
  49. mesW.className="mesWindow";
  50. mesW.innerHTML="<divclass='mesWindowTop'><tablewidth='100%'height='100%'><tr><td>"+wTitle+"</td><tdstyle='width:1px;'><inputtype='button'onclick='closeWindow();'title='关闭窗口'class='close'value='关闭'/></td></tr></table></div><divclass='mesWindowContent'id='mesWindowContent'>"+content+"</div><divclass='mesWindowBottom'></div>";
  51. styleStr="left:"+(((pos.x-wWidth)>0)?(pos.x-wWidth):pos.x)+"px;top:"+(pos.y)+"px;position:absolute;width:"+wWidth+"px;";
  52. mesW.style.cssText=styleStr;
  53. document.body.appendChild(mesW);
  54. }
  55. functionshowBackground(obj,endInt)
  56. {
  57. obj.filters.alpha.opacity+=1;
  58. if(obj.filters.alpha.opacity<endInt)
  59. {
  60. setTimeout(function(){showBackground(obj,endInt)},8);
  61. }
  62. }
  63. //关闭窗口
  64. functioncloseWindow()
  65. {
  66. if(document.getElementById('back')!=null)
  67. {
  68. document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
  69. }
  70. if(document.getElementById('mesWindow')!=null)
  71. {
  72. document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
  73. }
  74. if(isIe){
  75. setSelectState('');}
  76. }
  77. //测试弹出
  78. functiontestMessageBox(ev)
  79. {
  80. varobjPos=mousePosition(ev);
  81. messContent="<divstyle='padding:20px020px0;text-align:center'>消息正文</div>";
  82. showMessageBox('窗口标题',messContent,objPos,350);
  83. }
  84. </script>
  85. </head>
  86. <body>
  87. <divstyle="padding:20px">
  88. <divstyle="text-align:left";><ahref="#none"onclick="testMessageBox(event);">弹出窗口</a></div>
  89. <divstyle="text-align:left;padding-left:20px;padding-top:10px";><select><option>下拉</option></select>弹出窗口时会将其隐藏,关闭时会让其显示,目的是在IE中防止弹出的DIV挡不住下拉框</div>
  90. <divstyle="text-align:center";><ahref="#none"onclick="testMessageBox(event);">弹出窗口</a></div>
  91. <divstyle="text-align:right";><ahref="#none"onclick="testMessageBox(event);">弹出窗口</a></div>
  92. </div>
  93. </body>
  94. </html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics