日期:2014-05-16  浏览次数:20355 次

js定位层的问题
我现在做一个弹出层,但是存在定位不准确的问题

比如我做一个Div,代码如下

<body> </body> <script>
var   thisBox=document.createElement( "div ");
var   BorderColor= "red ";
var   BoxWidth=100;
var   BoxHight=100;
with   (thisBox)   {
setAttribute( "align ", "center ");
style.background   =   "white ";
style.border   =   "1px   solid   "   +   BorderColor;
style.position   =   "absolute ";
style.left   =   "50% ";
style.top   =   "50% ";
style.font= "12px/1.6em   Verdana,   Geneva,   Arial,   Helvetica,   sans-serif ";
style.marginLeft   =   "-225px "   ;
style.marginTop   =   (WebForm_GetScrollY()-75)+ "px ";
style.width   =   BoxWidth   +   "px ";
style.height   =   BoxHight   +   "px ";
style.textAlign   =   "center ";
style.lineHeight   = "25px ";
style.zIndex   =   "10001 ";
innerText   =   "我是内容 ";
//禁止选取文字和右键
attachEvent( "oncontextmenu ",new   Function( "return   false "));
attachEvent( "ondragstart ",new   Function( "return   false "));
attachEvent( "onselectstart ",new   Function( "return   false "));
}
document.body.appendChild(thisBox);


function   WebForm_GetClentX()  
{
if   (typeof   window.pageYOffset   !=   'undefined ')   {
return   window.pageXOffset;
}
else   {
if   (document.documentElement   &&   document.documentElement.clientWidth)   {
return   document.documentElement.clientWidth;
}
else   if   (document.body)   {
return   document.body.clientWidth;
}
        }
return   0;
}
function   WebForm_GetClentY()  
{
if   (typeof   window.pageYOffset   !=   'undefined ')   {
return   window.pageYOffset;
        }
else   {
if   (document.documentElement   &&   document.documentElement.clientHeight)   {
return   document.documentElement.clientHeight;
}
else   if   (document.body)   {
return   document.body.clientHeight;
}
        }
return   0;
}
function   WebForm_GetScrollX()  
{
if   (typeof   window.pageYOffset   !=   'undefined ')   {
return   window.pageXOffset;
        }
else   {
if   (document.documentElement   &&   document.documentElement.scrollLeft)   {
return   document.documentElement.scrollLeft;
}
else   if   (document.body)   {
return   document.body.scrollLeft;
}
}
return   0;
}
function   WebForm_GetScrollY()  
{
if   (typeof   window.pageYOffset   !=   'undefined ')   {
return   window.pageYOffset;
}
el