php+jquery+ajax滚动条滚动到底部自动加载,简单实现瀑布流

时间:2022-12-04 19:00:19

html代码:index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>演示瀑布流</title>
<script type="text/javascript" src="jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var num = 1; //计数器初始化为1
var maxnum = 10000; //设置一共要加载几次
$(window).scroll(function(){
//alert(1111);
checkload();
});

//建立加载判断函数
function checkload(){
var srollPos = $(window).scrollTop(); //滚动条距离顶部的高度
var windowHeight = $(window).height(); //窗口的高度
var dbHiht = $("body").height(); //整个页面文件的高度
s= setTimeout(function(){
if((windowHeight + srollPos) >= (dbHiht) && num != maxnum){
alert(num);
LoadList(num);
num++; //计数器+1
}
},500);
}

//创建ajax加载函数,并设置变量C,用于输入调用的页面频道,请根据实际情况判断使用,非必要。
function LoadList(c){
//alert("aaaa");
$.get("aaa.php", function(result){
//alert(result);
t = setTimeout(function(){$("#list_box").append(result+"<br/>")},1);
});
}
});
</script>
</head>
<div id="list_box" style="line-height:80px; font-size:12px;font-size:1.2rem">
AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAAA<br/>AAAAAAAAAAAAAAA<br/>
</div>
<body>
</body>
</html>

php代码:aaa.php

<?

echo "aaaaaaaaa<hr>";

?>