码迷,mamicode.com
首页 > 其他好文 > 详细

滚动条位置判断

时间:2017-12-14 14:48:30      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:scrollto   获取   else   func   top   scroll   判断   blog   gpo   

//获取滚动条距离顶部位置
function getScrollTop() {
var scrollTop = 0;
if (document.documentElement && document.documentElement.scrollTop) {
scrollTop = document.documentElement.scrollTop;
} else if (document.body) {
scrollTop = document.body.scrollTop;
}
return scrollTop;
}
//获取当前可视范围的高度
function getClientHeight() {
var clientHeight = 0;
if (document.body.clientHeight && document.documentElement.clientHeight) {
clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
} else {
clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
}
return clientHeight;
}
//获取文档完整的高度
function getScrollHeight() {
return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
}
//判断滚动条是否达到底部
getScrollTop() + getClientHeight() == getScrollHeight()

滚动条位置判断

标签:scrollto   获取   else   func   top   scroll   判断   blog   gpo   

原文地址:http://www.cnblogs.com/zyxing/p/8037446.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!