就是啊
你选择定位效果看看是不是滚动条滚动位置不变
你看固定定位部分的说明【固定定位】这里“固定定位”的意思是当滚动滚动条时,高亮层依然保持在浏览器对应的位置上。同样对于支持fixed的浏览器很简单,只要把position设为fixed就行了,这个样式本来就是这样用的,但可怜的ie6只能模拟了。ie6模拟的原理是在onscroll事件中,不断根据滚动的距离修正top和left。
首先设置position未absolute,并记录当前scrollTop和scrollLeft的值,给onscroll事件添加定位函数_fixed:Code
this.Box.style.position = "absolute";
this._top = document.documentElement.scrollTop; this._left = document.documentElement.scrollLeft;
window.attachEvent("onscroll", this._fixed);
其中定位函数_fixed是这样的:Code
var iTop =  document.documentElement.scrollTop - this._top + this.Box.offsetTop, iLeft = document.documentElement.scrollLeft - this._left + this.Box.offsetLeft;
    
this.Box.style.top = iTop + "px"; this.Box.style.left = iLeft + "px";
    
this._top = document.documentElement.scrollTop; this._left = document.documentElement.scrollLeft;
原理也很简单,就是把当前scrollTop减去_top值(上一个scrollTop值)再加上当前的offsetTop,就得到要设置的top值了。

解决方案 »

  1.   

    网页可见区域宽: document.body.clientWidth
    网页可见区域高: document.body.clientHeight
    网页可见区域宽: document.body.offsetWidth (包括边线的宽)
    网页可见区域高: document.body.offsetHeight (包括边线的高)
    网页正文全文宽: document.body.scrollWidth
    网页正文全文高: document.body.scrollHeight
    网页被卷去的高: document.body.scrollTop
    网页被卷去的左: document.body.scrollLeft
    网页正文部分上: window.screenTop
    网页正文部分左: window.screenLeft
    屏幕分辨率的高: window.screen.height
    屏幕分辨率的宽: window.screen.width
    屏幕可用工作区高度: window.screen.availHeight
    屏幕可用工作区宽度: window.screen.availWidth
      

  2.   

    <html>
    <head><title>ddd</title>
    <script>
    function init(){
    var tops = document.body.offsetHeight - 35 + document.body.scrollTop;//35为浏览器边线的高
            if (document.body.scrollWidth > document.body.clientWidth) {
    tops = tops - 15;//15为横向滚动条的高
    }
    floatDiv.style.top = tops;
            floatDiv.style.left = 0 + document.body.scrollLeft;
            floatDiv.style.display = "block";
    }
    </script>
    </head>
    <body onload="init();window.onscroll = init;">
        <div style="height:1800px; width: 1800px;">ddddddddddddddddddddddddddddd</div>
        <div align="center" style="position: absolute; top: 470; background: red; line-height: 30px;
            background: #CCCCCC; background: red;" id="floatDiv">
            我就浮动在这....
        </div>
    </body>
    </html>
    <!-- 方法比较愚蠢,别见怪哈   在IE7下测试通过 -->
      

  3.   


    <div style='overflow: auto; height: 500px; width: 400px;' id="scrollDiv">
        <div style="height: 1000px; background: #f7f7f7">
        </div>
        <div align="center" style="position: absolute; top: 470; background: red; line-height: 30px;
            background: #CCCCCC; background: red" id="floatDiv">
            我就浮动在这....
        </div>
    </div><script>
    function window.onscroll(){   
        document.getElementById('floatDiv').style.top=document.body.scrollTop + "px";
    }
    var h = parseInt(document.getElementById('floatDiv').style.top);
    function scrollDiv.onscroll(){  
        document.getElementById('floatDiv').style.top=h + scrollDiv.scrollTop + "px";
    }
    </script>
    解决