-
-
Save shuiRong/f39992502e110ab9229952f1004a3b31 to your computer and use it in GitHub Desktop.
滚动监听
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(window).scroll(function(){ | |
//下面这句主要是获取网页的总高度,主要是考虑兼容性所以把Ie支持的documentElement也写了,这个方法至少支持IE8 | |
// 获取当前页面滚动条纵坐标的位置(页面滚动条总高度) | |
var htmlHeight = | |
document.body.scrollHeight || document.documentElement.scrollHeight; | |
//clientHeight是网页在浏览器中的可视高度, | |
var clientHeight = document.documentElement.clientHeight; | |
//scrollTop是浏览器滚动条的top位置, | |
var scrollTop = | |
document.body.scrollTop || document.documentElement.scrollTop; | |
//通过判断滚动条的top位置与可视网页之和与整个网页的高度是否相等来决定是否加载内容; | |
console.log(scrollTop, '__', clientHeight, '__', htmlHeight); | |
if (scrollTop + clientHeight >= htmlHeight) { | |
console.log(1); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
滚动条高度:
window.scrollY