当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 基于滚动条位置判断的简单实例

基于滚动条位置判断的简单实例

2018年02月23日  | 移动技术网IT编程  | 我要评论

实例如下所示:

//获取滚动条距离顶部位置
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()

以上这篇基于滚动条位置判断的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网