如果我理解得很好,你需要一个类似的代码,在这段代码中,当用户(通过滚动)距离最后一个元素 4000 像素(在本例中为 div.newDeal:最后)(是一个很长的网络)。
$(document).ready(function() {
//global variable in this script to test if I already made the request ajax ( I dont
//want to make continious ajax request)
var loaded=false;
$(window).bind('scroll', handlerScroll); //attach event to the scroll
})//end document ready
//FIRE AUTOSCROLL (FIRE REQUEST AJAX)
//*************************************
var handlerScroll=function (){
//get position of the scroll
var space=$('#listdeals div.newDeal:last').offset().top - $(window).scrollTop();
//if that distance is less than (or the middle, or the bottom). fire the request ajax
if (space<= 4000 && jQuery('div.previousDeal').size()==0){
//disable scroll event
$(window).unbind();
//
//build data post
//
var parameters="actionAutoscroll=true&"+.........;
//MAKE REQUEST AJAX
//********************
$.ajax({
url: "/offers",
type:'POST',
data: parameters,
success: process_previousDeals
}); //end ajax
return false;
}
}//end if load previous deals depending of scroll
}//end handler
function process_previousDeals(results){
//inject new content in the page
}