如题,网上查找了一下,谢谢分享方法的大神,自己整理,代码如下
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>title</title>
<script src="jquery.min.js"></script>
</head>
<body style="height: 2000px;">
</body>
<script>
$(function(){
// 取窗口滚动条高度
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){
var clientHeight = (document.body.clientHeight<document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
}else{
var clientHeight = (document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
}
return clientHeight;
}
// 取文档内容实际高度
function getScrollHeight(){
return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
}
// 判断是否到达底部
function scrollAtBottom(){
if (getScrollTop()+getClientHeight()==getScrollHeight()){
return true;
}else{
return false;
}
}
$(window).scroll(function(){
if (scrollAtBottom()){
console.log("到达底部");
}else{
console.log("没有到达底部");
}
})
})
</script>
</html>