使用Javascript确定何时滚动到页面底部 [英] Determining when scrolled to bottom of a page with Javascript

查看:164
本文介绍了使用Javascript确定何时滚动到页面底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定何时滚动到页面底部(不使用任何JS库),但到目前为止,我对使用以下哪一项感到困惑。我见过的最有希望的是 window.scrollY ,但即使滚动到页面底部,它也永远不会匹配窗口的值.innerHeight 。最好的方法是什么?

I'm trying to determine when I've scrolled to the bottom of the page (without using any JS library), but so far, I'm a bit confused over which one of the following to use. The most promising one I've seen is window.scrollY, but even when scrolled to the bottom of the page, it never matches the value of window.innerHeight. What's the best way to do this?

window.innerWidth
window.innerHeight

window.outerWidth
window.outerHeight

window.scrollX
window.scrollY

document.body.scrollWidth
document.body.scrollHeight
document.body.scrollTop
document.body.scrollLeft

document.body.offsetTop
document.body.offsetLeft
document.body.offsetWidth
document.body.offsetHeight


推荐答案

何时 window.innerHeight + document.body.scrollTop 大于或等于 document.body.offsetHeight 然后你在底部

when window.innerHeight + document.body.scrollTop is greater than or equal to document.body.offsetHeight then you are at bottom

但由于IE有这些属性的问题,你需要使用其他属性,比如

but since IE has issues with these properties you need to use alternative properties, like

document.documentElement.scrollTop 用于滚动, document.documentElement.clientHeight 用于窗口高度

document.documentElement.scrollTop for the scroll and document.documentElement.clientHeight for the window height

完整代码: http://jsbin.com/egegu3/6/edit

这篇关于使用Javascript确定何时滚动到页面底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆