by nolovelust
9. February 2011 12:21
To create a simple infinite scrolling / paging with jQuery like on Twitter that loads data as you scroll down, all you need is to copy couple of lines of code below.
Code finds scrolling position and triggers your load function. You don't need any plugin at all. Here is the sample:
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
$('#morepages').trigger("click");
}
});
function loadBookmarksAddToLi(folderId, startRow) {
showProgress();
$.get('AjaxListBookmarks.aspx?folderId=' + folderId + '&startRow=' + startRow , function (data) { appendData(data) });
$("li[rel^='moreli']").remove();
}
</sript>
<ul>
<li><a href="http://foo-domain.com">foo</a></li>
<li id="moreli" rel="moreli0"><a href="#" id="morepages" onclick="loadBookmarksAddToLi(0,0); return false;">More</a></li>
</ul>