滚动到底部再计算 clientHeight+scrollHeight

解决方案 »

  1.   


    整个页面高度:document.body.scrollHeight显示区域高度:document.body.clientHeight
      

  2.   

    我试过了,SCROLLHEIGHT不是,只是当前滚屏到的高度。如果还没有滚动到底,那么就不是最后的高度。
      

  3.   

    楼主试的是什么?scrollHeight和滚动条滚动到哪没有关系。
    测试可以用下面的程序。
    楼主试的应该是scrollTop属性。
    <script language=javascript>
    function hehe()
    {
    alert(document.body.scrollHeight)
    }
    </script>
    <input name=button1 type=button value="按" onclick="hehe()"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
    <input name=button1 type=button value="按" onclick="hehe()"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
    <input name=button1 type=button value="按" onclick="hehe()"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
    <input name=button1 type=button value="按" onclick="hehe()"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
    <input name=button1 type=button value="按" onclick="hehe()"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
    <input name=button1 type=button value="按" onclick="hehe()"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
    <input name=button1 type=button value="按" onclick="hehe()"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
    <input name=button1 type=button value="按" onclick="hehe()"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
    <input name=button1 type=button value="按" onclick="hehe()"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
      

  4.   

    scrollHeight注意文档类型声明<!DOCTYPE ...>
    IE6加入了Strict模式后,将IE窗口模型的部分body属性重新定义为document.documentElemnt(html)属性。可加入如下代码判别,已兼容Transitional/Strict模式<SCRIPT LANGUAGE="JavaScript">
    window.onload = function(){
    window["viewport"] = (document.documentElement && document.documentElement.clientHeight)?document.documentElement:document.body;
    alert(viewport.scrollHeight)
    }
    </SCRIPT>IE/FF对于viewport对象解析略有不同,scrollHeight数值上有所差异