js滚动加载到底部
2016-04-21 14:00
579 查看
<script>
//获取滚动条当前的位置
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);
};
window.onscroll = function () {
if (getScrollTop() + getClientHeight() == getScrollHeight()) {
alert("到达底部");
}
}
</script>
//获取滚动条当前的位置
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);
};
window.onscroll = function () {
if (getScrollTop() + getClientHeight() == getScrollHeight()) {
alert("到达底部");
}
}
</script>
相关文章推荐
- js/jq控制页面动态加载数据,滑动滚动条自动加载事件
- [转]Javascript中的自执行函数表达式
- js改变classname 或添加classname (转)
- js提交表单
- 浏览器加载外部js 的顺序,以及处理顺序。
- JavaScript转换与解析JSON的方法
- js/web 日程管理 插件
- swiperLeft/swiperRight以及js长按事件
- JavaScript 对象
- 60行JS实现俄罗斯方块
- javascript深入理解js闭包
- javascript textContent与innerText的异同分析
- JS HTML DOM
- js 控制frame的元素
- (礼拜四log)点击某元素外的时候,该元素隐藏的办法
- javaScript学习思维导向图
- moment.js
- js数组基本知识
- Angular.js中使用$watch监听模型变化
- 关于js的函数重载的问题