模仿微博拉動滾動條加載數據

<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>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章