模仿微博拉动滚动条加载数据

101 篇文章 1 订阅
41 篇文章 0 订阅
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>滚动条距离底部</title>
<script src="easyui1.2.4/jquery-1.6.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var i = 4;
$(window).bind("scroll", function (event) {
//滚动条到网页头部的 高度,兼容ie,ff,chrome
var top = document.documentElement.scrollTop + document.body.scrollTop;
//网页的高度
var textheight = $(document).height();
// 网页高度-top-当前窗口高度 
if (textheight - top - $(window).height() <= 100) {
if (i >= 100) {
return; //控制最大只能加载到100
}
$('#div1').css("height", $(document).height() + 100);
i++; 
//可以根据实际情况,获取动态数据加载 到 div1中
$('<div>' + i + '</div>').appendTo($('#div1'));
}
});

})


</script>
<style>
#div1 div{ font-size:100px; background:#ccc;margin-top:5px}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 1000px;" id="div1">
<div>
1</div>
<div>
2</div>
<div>
3</div>
<div>
4</div>
</div>
</form>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值