我需要检查某个元素距离页面底部是否为 x 像素,以动态加载新内容。目前,即使栏位于底部,scrollTop 和高度也不匹配。
允许使用 jquery,尽管基本的 javascript 会更有帮助。
您可能想尝试以下操作(仅在 Firefox 3.5 和 IE 8 中测试):
function pollScrollPosition() {
var y = (document.all) ? document.body.scrollTop : window.pageYOffset;
var max = window.scrollMaxY ||
(document.body.scrollHeight - document.body.clientHeight);
if ((max - y) < 100) {
console.log('Within the bottom 100 pixels. Do Something!');
}
}
// Check the scroll position every 250ms
setInterval(pollScrollPosition, 250);
Firebug 中上述示例的屏幕截图:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)