1

我正在使用 WebBrowser 控件为 Windows 手机开发浏览器应用程序。我正在尝试使用以下代码实现自动滚动到底部。它工作正常,但是当页面document.body.scrollHeight在条件检查中放大时

if (document.body.scrollHeight > (document.documentElement.scrollTop + window.innerHeight))

总是更大,导致函数被不间断地调用并且clearTimeout(timeOutDown)永远不会到达终止。

var timeOutDown;
function scrollToBottom() 
{ 
    clearTimeout(timeOut);
    if (document.body.scrollHeight > (document.documentElement.scrollTop + window.innerHeight))
    {
         window.scrollBy(0, 100); 
         window.external.notify(String(window.innerHeight));
         timeOutDown=setTimeout('scrollToBottom()',10);
    }
     else 
    {
        clearTimeout(timeOutDown);
    }
}

考虑到用户可以放大/缩小页面,这样做的正确方法是什么?

4

1 回答 1

2

想通了,document.documentElement.scrollTop换成window.pageYOffset. 所以条件语句变成

if (document.body.scrollHeight > (window.pageYOffset + window.innerHeight))

这将处理缩放系数。

于 2013-10-09T02:49:54.920 回答