我正在使用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);
}
}
考虑到用户可以放大/缩小页面,这样做的正确方法是什么?
答案 0 :(得分:2)
想出来,只需将document.documentElement.scrollTop
替换为window.pageYOffset
即可。因此条件语句变为
if (document.body.scrollHeight > (window.pageYOffset + window.innerHeight))
这将照顾缩放系数。