在jQuery中已经回答了同样的问题,但我正在寻找不使用jQuery的解决方案。 如何确定垂直滚动条是否到达网页底部
我想知道如何确定垂直滚动条是否已经到达了网页底部。
我正在使用Firefox3.6
我编写了一个简单的JavaScript循环来向下滚动200像素,当滚动条到达页面底部时,我希望停止循环。
问题是scrollHeight()返回1989。
而在循环内,scrollTop
每次迭代都会增加200。
200 ==> 400 ==> 600 .... 1715
从1715开始,它不会增加,所以这个循环将无限继续。
看起来scrollHeight()和scrollTop()不是确定滚动条实际位置的正确方法?我怎样才能知道循环何时应该停止?
代码:
var curWindow = selenium.browserbot.getCurrentWindow();
var scrollTop = curWindow.document.body.scrollTop;
alert('scrollHeight==>' + curWindow.document.body.scrollHeight);
while(curWindow.document.body.scrollHeight > curWindow.document.body.scrollTop) {
scrollTop = curWindow.document.body.scrollTop;
if(scrollTop == 0) {
if(window.pageYOffset) { //firefox
alert('firefox');
scrollTop = window.pageYOffset;
}
else { //IE
alert('IE');
scrollTop = (curWindow.document.body.parentElement) ? curWindow.document.body.parentElement.scrollTop : 0;
}
} //end outer if
alert('current scrollTop ==> ' + scrollTop);
alert('take a shot here');
selenium.browserbot.getCurrentWindow().scrollBy(0,200);
} //end while