<HTML>
<script>
function divcenter(){
document.all.mxh.style.left=(Math.round((document.body.scrollWidth-200)/2)).toString()+"px"
}
</script>
<body onload="divcenter()" onresize=divcenter()>
<table width=100%>
<tr>
<td>test
</td>
</tr>
</table>
<div id=mxh style="position:absolute;left:200px;top:30px;width:200px;height:200px;background-color:navy;border:2px">测试文字</div>
</HTML>

解决方案 »

  1.   

    我是要在窗口内容超过一屏以上时显示div,最好是跟mouse走,但是当窗口内容超过一屏以上时,div会显示在非显示区。
      

  2.   

    你自己再完善一下:<html><head><SCRIPT LANGUAGE=javascript FOR=window EVENT=onscroll><!--
      var aa = document.all.testdiv;
      var h2 = document.all.img1.clientHeight; //图片的高度
      aa.style.pixelTop=document.body.scrollTop+document.body.clientHeight-h2-10;
    //--></SCRIPT></HEAD>
    <BODY><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><div id='testdiv' style="POSITION:absolute;Left:300;Top:300">
    <img src=http://www.csdn.net/images/csdn.gif border=0 id=img1>
    </div></body></html>