• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Shiaupo
知识要善于积累,技术更需要总结。
博客园    首页    新随笔    联系   管理    订阅  订阅
判断滚动条是否到达底端
 1         //取窗口滚动条高度 
 2         function getScrollTop() {
 3             var scrollTop = 0;
 4             if (document.documentElement && document.documentElement.scrollTop) {
 5                 scrollTop = document.documentElement.scrollTop;
 6             }
 7             else if (document.body) {
 8                 scrollTop = document.body.scrollTop;
 9             }
10             return scrollTop;
11         }
12 
13 
14         // 取窗口可视范围的高度 
15         function getClientHeight() {
16             var clientHeight = 0;
17             if (document.body.clientHeight && document.documentElement.clientHeight) {
18                 var clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
19             }
20             else {
21                 var clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
22             }
23             return clientHeight;
24         }
25 
26         // 取文档内容实际高度 
27         function getScrollHeight() {
28             return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
29         }

滚动条到达底部的条件:getScrollTop() + getClientHeight() == getScrollHeight()

 

 

posted on 2011-11-08 16:39  Shiaupo  阅读(505)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3