jquery滚动到页面底部问题

源码:

$(window).scroll(function () {
  var scrollTop = $(this).scrollTop()
  var scrollHeight = $(document).height()
  var windowHeight = $(this).height()

  console.log(`scrollTop: ${scrollTop}`)
  console.log(`windowHeight: ${windowHeight}`)
  console.log(`scrollHeight: ${scrollHeight}`)

})

为啥当页面滚动到底部时, scrollTop + windowHeight 的总大小 [大于] scrollHeight , 不是应该相等才对吗?

阅读 4.2k
2 个回答

@yhhwpp 网上流传滚动到底部ajax加载条件不就是 scrollTop + windowHeight = scrollHeight么?

document的高度是整个文档流的高度。可以无穷大。
window的高度只是你窗口的实际高度(高度受限于你的显示器屏幕)。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进