急~~在线等,javascript居中问题

来源:百度知道 编辑:UC知道 时间:2024/05/23 11:07:43
divHeight = parseInt(document.getElementById("eMeng").offsetHeight,10)
divWidth = parseInt(document.getElementById("eMeng").offsetWidth,10)
docWidth = document.body.clientWidth;
docHeight = document.body.clientHeight;
document.getElementById("eMeng").style.top = docHeight - divHeight + parseInt(document.body.scrollTop,10)
document.getElementById("eMeng").style.left = docWidth - divWidth + parseInt(document.body.scrollLeft,10)
把这段代码变成垂直居中的,谢谢各位大侠了,我也没有多少分了,谢谢了
最好是能给我解释一下是什么意思,我会再给加分的

<html>

<head>

<title></title>
<style>
#eMeng{
position :absolute ;
height:5px;
width : 10px ;
background-color : #000 ;
margin : 20px 20px ;}
</style>
</head>
<div id="eMeng"></div>
<body>

</body>
<script language="javascript" type="text/javascript">
divHeight = parseInt(document.getElementById("eMeng").style.height,10) ;//获得对象高度
alert(divHeight);
divWidth = parseInt(document.getElementById("eMeng").style.width,10) ;//获得对象宽度
alert(divWidth);
docWidth = document.body.clientWidth; //窗口可用范围宽度
alert(docWidth);
docHeight = document.body.clientHeight; //窗口可用范围高度
alert(docHeight);
document.getElementById("eMeng").style.top = (docHeight - divHeight + parseInt(document.body.scrollTop,10))/2 ;//绝对定位到窗口垂直中央<