<!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=utf-8" />
<title>滚动加载</title>
</head>
<script src="file:///D|/wamp/www/Js/jquery-1.10.2.min.js" type="text/javascript"></script>
<body>
<div id="loading"></div>
<div style="width:auto; height:1000px;">
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#loading").html("正在加载...");
setTimeout("getData()", 1500);
});
var s = setInterval("isShow()", 1500);//每隔1.5秒判断滚动条是否在2/3处,是的话加载数据
var isShow = function() {//判断是否显示数据
if ($(window).scrollTop() + $(window).height() >= $(document).height()*2/3) {
$("#loading").html("正在加载....");
setTimeout("getData()", 1500);
}
};
var getData = function() {//Ajax获取服务器数据
$.ajax({//初始化
url: "Service.aspx",
type: 'GET',
data: { page: getPage() },
dateType: 'html',
timeout: 120000,
success: function(msg) {
if (msg == "") {
clearInterval(s);//循环停止
$("#loading").html("加载完成了");
return false;
} else {
$("#documentDiv").append(msg);
$("#pIndex").val(getPage() + 1);
$("#loading").html("");
}
}
});
};
var getPage = function() {//获得当前页码
return parseInt($("#pIndex").val());
};
</script>
</body>
</html>
js滚动加载内容
最新推荐文章于 2024-07-16 17:26:59 发布