浮动的不能自动在中间 但是可以通过设置LEFT和TOP来实现
利用以下方法动态获取网页的高度和宽度
网页可见区域宽: document.body.clientWidth
网页可见区域高: document.body.clientHeight
然后通过获得的值进行计算得到居中的LEFT和TOP值以下为相关操作:
网页可见区域宽: document.body.offsetWidth (包括边线的宽)
网页可见区域高: document.body.offsetHeight (包括边线的高)
网页正文全文宽: document.body.scrollWidth
网页正文全文高: document.body.scrollHeight
网页被卷去的高: document.body.scrollTop
网页被卷去的左: document.body.scrollLeft

解决方案 »

  1.   

    不好意思啊,我可能意思说错了,我的意思是div悬浮在页面的中间,就是没有滚动条的时候中间位置,就算有滚动条,它还是悬浮在页面的中间,不算超过的页面,只算当前可视化的页面中间
      

  2.   

    http://www.btbtd.org/test/sqJsTools/tools/FixBox/FixBox2/demo/default.shtml
      

  3.   

    具体JS实现:
    var iNodeWidth = parseInt(document.getElementById("对象ID").style.width);
    var iNodeHeight= parseInt(document.getElementById("对象ID").style.height);
    window.onscroll = function()
    {
       var iNowLeft = (parseInt(document.body.clientWidth)/2-iNodeWidth/2)+parseInt(document.body.scrollLeft);
       var iNowTop  = (parseInt(document.body.clientHeight)+/2-iNodeHeight/2)++parseInt(document.body.scrollHeight);
       document.getElementById("对象ID").style.left = iNowLeft;
       document.getElementById("对象ID").style.top  = iNowTop;  
    }
    试试看
      

  4.   

    http://www.cnblogs.com/cloudgamer/archive/2008/09/15/1290954.html参考这里的定位效果