jquery实现随滚动条滚动而加载数据的功能,目前比较流行的瀑布流就是这种实现形式,具体代码以及使用方法如下:
拉动滚动条加载数据$(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中
$('
' + i + '
').appendTo($('#div1'));
}
});
})
#div1 div
{
font-size: 100px;
background: #ccc;
margin-top: 5px;
}