网站div浮动层同时网站背景变灰代码兼容firefox,谷歌浏览器(Chrome)效果图:
Sign in处代码:<a class="signinlink" onclick="javascript:ShowLoginWindow()">Sign in</a>
function ShowLoginWindow()
{
if(document.getElementById("fullbg"))
{
document.body.removeChild(document.getElementById("fullbg"));
}
if(document.getElementById("deliverywin"))
{
document.body.removeChild(document.getElementById("deliverywin"));
}
deliverywinopen();
}
function deliverywinopen()
{
var bgDiv=document.createElement("div");
bgDiv.id="fullbg";
bgDiv.className="fullwinbg";
bgDiv.style.width=document.body.scrollWidth+"px";
var scrollHeight=document.body.scrollHeight+20;
bgDiv.style.height=scrollHeight+"px";
bgDiv.innerHTML="<iframe frameborder=\"0\" scrolling=\"no\" src=\"about:blank\" style=\"background-color:#FFFFFF;width:"+document.body.scrollWidth+"px;height:"+scrollHeight+"px;\"></iframe>";
document.body.appendChild(bgDiv);
var deliverywin=document.createElement("div");
deliverywin.id="deliverywin";
deliverywin.className="deliverywindow";
deliverywin.innerHTML="<iframe id=\"deliveryiframe\" frameborder=\"0\" allowtransparency=\"true\" scrolling=\"no\" src=\"loginifram.aspx\" style=\" width:220px; height:310px;\"></iframe>";
/* var mouse=mouseCoords(document.getElementById("Table13"));
var x=mouse.x+217;
var y=mouse.y+130;
deliverywin.style.left=x+"px";
deliverywin.style.top=y+"px";*/
document.body.appendChild(deliverywin);
centerwh(deliverywin);
}
function centerwh(obj)
{
var h1 = document.body.clientHeight;
var h2 = document.documentElement.clientHeight;
var isXhtml = (h2<=h1&&h2!=0)?true:false;
var body = isXhtml?document.documentElement:document.body;
var wh={left:0,top:0};
var vwh={w:0,h:0};
vwh.w=navigator.userAgent.indexOf('MSIE') >= 0?parseInt(body.clientWidth):parseInt(window.innerWidth);
vwh.h=navigator.userAgent.indexOf('MSIE') >= 0?parseInt(body.clientHeight):parseInt(window.innerHeight);
wh.left=(vwh.w/2)-108;
wh.top=document.documentElement.scrollTop+document.body.scrollTop+(vwh.h/2)-150;这个地方要注意:即获取高度时使用document.documentElement.scrollTop+document.body.scrollTop,经测试,代码在IE、Firefox、Chrome下都能显示正常了。
document.getElementById("deliverywin").style.top = wh.top + "px";
document.getElementById("deliverywin").style.left = wh.left + "px";
}
function windowclose()
{
if(document.getElementById("fullbg"))
{
document.body.removeChild(document.getElementById("fullbg"));
}
if(document.getElementById("deliverywin"))
{
document.body.removeChild(document.getElementById("deliverywin"));
}
}
在loginifram.aspx页面处的关闭代码:<a href="#" class="two" onClick="parent.windowclose();">close</a>
网站div浮动层同时网站背景变灰代码兼容firefox,谷歌浏览器(Chrome)讲解完成.
作者: 网站设计@ 企业网站管理系统
原载: 25亿企业网站管理系统
版权所有。转载时必须以链接形式注明作者和原始出处及本声明。