Chinaunix首页 | 论坛 | 博客
  • 博客访问: 76220
  • 博文数量: 73
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 740
  • 用 户 组: 普通用户
  • 注册时间: 2014-07-04 16:50
文章分类
文章存档

2014年(73)

我的朋友

分类: Html/Css

2014-08-20 10:38:56

Js弹出DIV遮罩层并在页面居中显示效果,这两天要用到正好练练手,比想象中碰到的问题要多,比如: ie6背景透明 ie6居中显示 还有对js对象的理解

openID=显示按钮,conID=需要显示的div,closeID=关闭按钮 

解决了: 
1.可以遮挡ie6下的select元素 但是在ie6下div没有透明度 
2.弹出的div可以一直在浏览器屏幕中间显示 

问题: 
1.目前不支持.class 只支持#id 
2.需要显示的div需要自己设置css 
3.在ie6下需要设置css 
例如div {_position: absolute;_top: expression(documentElement.scrollTop + 340 + "px"); } 
4.ie6下背景div没有透明度 这里我上网搜到的结果都不能解决 如果您有方法请给我留言

演示代码:

点击(此处)折叠或打开

  1. <!DOCTYPE HTML>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title></title>
  5. <style type="text/css">
  6. *{margin:0;padding:0;}
  7. #bt{border: 2px solid #000;background-color: #ccc;cursor: pointer;padding: 2px 5px;}
  8. /****订单弹出框*****/
  9. .VeryhuoCOM{ position:fixed;_position: absolute;_top: expression(documentElement.scrollTop + 340 + "px"); background:#fff; border:1px solid #939395; width:500px; height:340px;top: 50%;left: 50%;margin: -200px 0 0 -250px; overflow:hidden; z-index:99999; font-size:14px; color:#000; display:none;}
  10. .VeryhuoCOM dl{ overflow:hidden; padding:20px; margin:0;}
  11. .VeryhuoCOM dl dt{ line-height:30px;}
  12. .VeryhuoCOM dl dd{ line-height:25px; height:25px; padding-left:10px; margin:0;}
  13. .VeryhuoCOM dl dd label{ padding-left:5px;}
  14. .VeryhuoCOM dl dd.cBtn{ width:102px; height:28px; background:url(../images/member/chooseBtn.gif) no-repeat; margin-top:10px; padding:0;}
  15. .VeryhuoCOM dl dd.cBtn a{ display:block; text-align:center;}
  16. .VeryhuoCOM dl dd.cBtn a:link,.VeryhuoCOM dl dd.cBtn a:visited{ color:#000;}
  17. .VeryhuoCOM dl dd.lBtn{ float:left; display:inline; margin-left:100px;}
  18. .VeryhuoCOM dl dd.rBtn{ float:left; display:inline; margin-left:10px;}
  19. </style>
  20. </head>
  21. <body>
  22. <a id="bt">点击弹出div</a>
  23. <div style="height:1000px;">
  24. sdfdsf
  25. <select>
  26. <option>Volvo</option>
  27. <option selected="selected">Saab</option>
  28. <option>Mercedes</option>
  29. <option>Audi</option>
  30. </select>
  31. </div>
  32. <a id="bt">点击弹出div</a>
  33. <div style="height:1000px;">
  34. sdfdsf
  35. <select>
  36. <option>Volvo</option>
  37. <option selected="selected">Saab</option>
  38. <option>Mercedes</option>
  39. <option>Audi</option>
  40. </select>
  41. </div>
  42. <div id="VeryhuoCOM" class="VeryhuoCOM" style="display: none;">
  43. <dl>
  44. <dt>请您告知我们取消订单的原因,以便我们改进。非常感谢!</dt>
  45. <dd><input type="radio" name="reason" id="reason1"><label for="reason1">改变主意,现在不想买了</label></dd>
  46. <dd><input type="radio" name="reason" id="reason2"><label for="reason2">刚才信息填错了,要重新下单</label></dd>
  47. <dd><input type="radio" name="reason" id="reason3"><label for="reason3">先取消,再更换或添加新商品</label></dd>
  48. <dd><input type="radio" name="reason" id="reason4"><label for="reason4">网银,信用卡等支付有问题</label></dd>
  49. <dd><input type="radio" name="reason" id="reason5"><label for="reason5">等待时间过长,不耐烦了</label></dd>
  50. <dd><input type="radio" name="reason" id="reason6"><label for="reason6">商品价格较贵</label></dd>
  51. <dd><input type="radio" name="reason" id="reason7"><label for="reason7">出现商品缺货情况</label></dd>
  52. <dd><input type="radio" name="reason" id="reason8"><label for="reason8">其它的原因</label></dd>
  53. <dd><input type="radio" disabled="disabled"><label>72小时到期自动取消(不可选)</label></dd>
  54. <dd class="cBtn lBtn"><a href="#">选好了</a></dd><dd class="cBtn rBtn"><a href="#" onclick="" id="close">点击取消</a></dd>
  55. </dl>
  56. </div>
  57. <script type="text/javascript">
  58. /*
  59. openID=显示按钮,conID=需要显示的div,closeID=关闭按钮
  60. Downloads By http://www.veryhuo.com
  61. 解决了:
  62. 1.可以遮挡ie6下的select元素 但是在ie6下div没有透明度
  63. 2.弹出的div可以一直在浏览器屏幕中间显示
  64. 问题:
  65. 1.目前不支持.class 只支持#id
  66. 2.需要显示的div需要自己设置css
  67. 3.在ie6下需要设置css
  68. 例如div {_position: absolute;_top: expression(documentElement.scrollTop + 340 + "px"); }
  69. 4.ie6下背景div没有透明度 这里我上网搜到的结果都不能解决 如果您有方法请给我留言
  70. */
  71. var _CalF = { //便捷方法
  72. $ : function(id){return document.getElementById(id)},
  73. create : function(id){return document.createElement(id)},
  74. append : function(id){return document.body.appendChild(id)},
  75. remove : function(id){return document.body.removeChild(id)}
  76. }
  77. function popup(openID,conID,closeID){
  78. this.onclick(openID,conID,closeID);
  79. }
  80. popup.prototype = {
  81. cssStyle : "width:100%;position:absolute;left:0;top:0;filter:alpha(opacity = 50);opacity:0.5;border:0;overflow:auto;",
  82. createShadowDiv : function(){ //背景遮罩
  83. var shadowDiv = _CalF.create("div");
  84. shadowDiv.id = "shadowDiv";
  85. shadowDiv.style.cssText = this.cssStyle;
  86. shadowDiv.style.height = document.body.scrollHeight + "px";
  87. shadowDiv.style.backgroundColor = "#000"
  88. shadowDiv.style.zindex = 100;
  89. _CalF.append(shadowDiv);
  90. },
  91. createIframe : function(){ //iframe
  92. var iframe = _CalF.create("iframe");
  93. iframe.id = "shadowIframe";
  94. iframe.style.cssText = this.cssStyle;
  95. iframe.style.height = document.body.scrollHeight + "px";
  96. iframe.style.zindex = 99;
  97. _CalF.append(iframe);
  98. },
  99. removeDiv : function(){
  100. _CalF.remove(_CalF.$("shadowDiv"));
  101. _CalF.remove(_CalF.$("shadowIframe"));
  102. },
  103. onclick : function(openID,conID,closeID){
  104. var that = this;
  105. _CalF.$(openID).onclick = function(){
  106. if(window.ActiveXObject){ //ie6
  107. if(!window.XMLHttpRequest){
  108. document.body.style.cssText = "_background-image: url(about:blank);_background-attachment: fixed;";
  109. }
  110. }
  111. that.createIframe();
  112. that.createShadowDiv();
  113. _CalF.$(conID).style.display = "block";
  114. }
  115. document.getElementById(closeID).onclick = function(){
  116. _CalF.$(conID).style.display = "none";
  117. that.removeDiv();
  118. }
  119. }
  120. }
  121. var bt = new popup("bt","VeryhuoCOM","close");
  122. </script>
  123. </body>
  124. </html> <div style="text-align:center;margin:30px 0 0 0;"><hr style="color:#999;height:1px;">如不能显示效果,请按Ctrl+F5刷新本页</div>

阅读(1552) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~