用div层来实现页面半透明遮罩效果

实现效果: 弹出一个窗口的时候,窗口后面的页面变暗,并且不能操作

难点: 因为div 层是不能把select控件遮住的,所以要特殊处理,方法两种,一种是在弹出窗口下面加一层iframe来遮住select;第二种是所以要在弹出的时候,先把select控件隐藏,这里选择第二种方法

实现原理: 在页面上和弹出窗口中间加一个半透明的层,把页面的内容覆盖掉

代码:

 

<mce:script language="javascript"><!-- function Open() { //隐藏select控件 DispalySelect(0); //显示遮罩层 document.getElementById("divPageMask").style.display="block"; //处理遮罩层 resizeMask(); window.onResize = resizeMask; //显示弹出窗口 document.getElementById("divOpenWin").style.display="block"; } function Close() { //显示select控件 DispalySelect(1); //处理遮罩层 divPageMask.style.width = "0px"; divPageMask.style.height = "0px"; divOpenWin.style.display = "none"; window.onResize = null; document.getElementById("divOpenWin").style.display="none"; } //页面遮罩 function resizeMask() { divPageMask.style.width = document.body.scrollWidth; divPageMask.style.height = document.body.scrollHeight; divOpenWin.style.left = ((document.body.offsetWidth - divOpenWin.offsetWidth) / 2); divOpenWin.style.top = ((document.body.offsetHeight - divOpenWin.offsetHeight) / 2); } function DispalySelect(val) { //显示和隐藏select控件 var dispalyType; var arrdispalyType=["hidden","visible"]; var arrObjSelect=document.getElementsByTagName("select"); for (i=0;i<arrObjSelect.length;i++) { arrObjSelect[i].style.visibility=arrdispalyType[val]; } } // --></mce:script> <mce:style type="text/css"><!-- .body,td{font-size:12px} #divPageMask{background-color:white; filter:alpha(opacity=50);left:0px;position:absolute;top:0px;} #divOpenWin{background-color:#EEEEEE;position: absolute;left:0px;top:0px;display: none;z-index:50; width:300px;height:150px} --></mce:style><style type="text/css" mce_bogus="1"> .body,td{font-size:12px} #divPageMask{background-color:white; filter:alpha(opacity=50);left:0px;position:absolute;top:0px;} #divOpenWin{background-color:#EEEEEE;position: absolute;left:0px;top:0px;display: none;z-index:50; width:300px;height:150px} </style> <div id="divPageMask"></div> <div id="divOpenWin"><center><a href="javascript:Close();" mce_href="javascript:Close();">关闭</a></center></div> <label></label> <center> <table border="0" cellpadding="0" cellspacing="0" width="650"> <tbody> <tr> <td colspan="2" align="center" height="90"><p><img src="http://www.sopull.com/Images/Index/logo.gif" mce_src="http://www.sopull.com/Images/Index/logo.gif" height="60" width="250"></p> <p> </p> <p> </p></td> </tr> <tr> <td height="10" style="color:#666666;font-size:13px" mce_style="color:#666666;font-size:13px"> </td> </tr> </tbody> </table> <table bgcolor="#e1e1e1" border="0" cellpadding="0" cellspacing="1" height="85" width="650"> <tbody> <tr> <td align="center" bgcolor="#f9f9f9"><table height=50 cellspacing=0 cellpadding=0 width=600 style="margin-top:20px" mce_style="margin-top:20px"> <FORM name="f" action="http://www.sopull.com/ShopList.asp"> <tbody> <tr> <td class="searchbar_word">关键字:</td> <td width="241"><input type="text" name="k" size=30 /></td> <td align=middle width=101 class="searchbar_word">所在地:</td> <td align=middle width=97 id="cn"><mce:script language="javascript" src="http://www.sopull.com/Inc/Js/ListCity.asp?CityName=北京市" mce_src="http://www.sopull.com/Inc/Js/ListCity.asp?CityName=北京市"></mce:script></td> <td align=middle width=95><input name="s" type=submit value=" 搜 铺 "></td> </tr> </form> <tr> <td width="64" height="30"> </td> <td colspan="4" valign="middle" class="search_text">例如:餐厅;电器;超市 </table></td> </tr> </tbody> </table> </center> <p align="center"> </p> <p align="center"><a href="javascript:Open();" mce_href="javascript:Open();">打开遮罩</a></p> <p align="center"> </p> <table width="650" border="0" align="center" cellpadding="0" cellspacing="0"> <tbody> <!-- <tr> <td align="center" background="Images/Index/line_2.gif" width="580"><img src="Images/Index/line_2.gif" mce_src="Images/Index/line_2.gif" height="9" width="9"></td> </tr>--> <tr> <td class="link" align="center" height="30"><a href="#" mce_href="#" target=_blank><font color="#FF6600">免费提交店铺</font></a> |  <a class="toplink" href="#" mce_href="#">店铺推广</a> |  <a class="toplink" href="#" mce_href="#">关于搜铺</a> |  <a class=b href="#" mce_href="#" target=_blank>业务合作</a>  |  <a class="toplink" onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.sopull.com');return false;" href="http://www.sopull.com/#" mce_href="http://www.sopull.com/">设为首页</a> |  <a class="toplink" onClick="javascript:window.external.addFavorite('http://www.sopull.com/','搜铺网-中国最大店铺搜索引擎')" href="http://www.sopull.com/#" mce_href="http://www.sopull.com/">加入收藏</a> </td> </tr> <tr> <td align="center" height="30">©2007 搜铺网     粤ICP备07006767号</td> </tr> </tbody> </table>

你可能感兴趣的:(用div层来实现页面半透明遮罩效果)