jquery实现滚动计算方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>滚动应用</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.main p{
width: 200px;
height: 100px;
}
</style>
</head>
<body>
<div class="main">
<p>111</p>
<p>11</p>
<p>222</p>
<p>333</p>
<p>444</p>
<p>666</p>
<p>555</p>
<p>444</p>
<p>3232</p>
<p>666</p>
</div>
<script src="./js/jquery-1.9.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$(window).scroll(function(){
var scrollTop=Math.ceil($(this).scrollTop()); //滚动条的高度
var scrollHeight=Math.ceil($(this).height());//当前视图高度
var _h=$(document).height(); //页面总高度
if(scrollTop+scrollHeight>=_h){
console.log('ok'); //加载到底部输出
//loadData(); //数据加载
}
})
})
</script>
</body>
</html>