检查用户是否已滚动到底部。我正在制作一个分页系统(有点像Facebook),当用户滚动到底部时,内容会加载。我认为最好的方法是找出用户何时在页面底部,并运行Ajax查询来加载更多的帖子。唯一的问题是,我不知道如何检查用户是否已经使用jQuery滚动到页面底部。有什么想法吗?我需要找到一种方法来检查用户何时使用jQuery滚动到页面底部。
3 回答
慕姐8265434
TA贡献1813条经验 获得超2个赞
.scroll()window
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
}});document
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
alert("near bottom!");
}});100
千巷猫影
TA贡献1829条经验 获得超7个赞
$(document).height()
function getDocHeight() {
var D = document;
return Math.max(
D.body.scrollHeight, D.documentElement.scrollHeight,
D.body.offsetHeight, D.documentElement.offsetHeight,
D.body.clientHeight, D.documentElement.clientHeight );}$(document).height()
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == getDocHeight()) {
alert("bottom!");
}
});
浮云间
TA贡献1829条经验 获得超4个赞
element.scrollHeight - element.scrollTop === element.clientHeight
element.addEventListener('scroll', function(event){
var element = event.target;
if (element.scrollHeight - element.scrollTop === element.clientHeight)
{
console.log('scrolled');
}});scrollHeightclientHeightscrollTop
添加回答
举报
0/150
提交
取消
