4
我一直工作在一个网站,自动负载上滚动的新内容从MySQL数据库中。 但问题是,即使滚动可以忽略不计,它也会加载新内容。我的意思是它在滚动时加载新内容,而不是在页面结束时加载。 可滚动部分位于静态框架内。AJAX自动加载HTML5的部分
jQuery代码:
<script type="text/javascript">
$(document).ready(function() {
var track_load = 0; //total loaded record group(s)
var loading = false; //to prevents multipal ajax loads
var total_groups = <?php echo $total_groups; ?>; //total record group(s)
$('#results').load("autoload_process.php", {'group_no':track_load}, function() {track_load++;}); //load first group
$("#frames").scroll(function() { //detect page scroll
if($(window).scrollTop() + $(window).height() == $(document).height()) //user scrolled to bottom of the page?
{
if(track_load <= total_groups && loading==false) //there's more data to load
{
loading = true; //prevent further ajax loading
$('.animation_image').show(); //show loading image
//load data from the server using a HTTP POST request
$.post('autoload_process.php',{'group_no': track_load}, function(data){
$("#results").append(data); //append received data into the element
//hide loading image
$('.animation_image').hide(); //hide loading image once data is received
track_load++; //loaded group increment
loading = false;
}).fail(function(xhr, ajaxOptions, thrownError) { //any errors?
alert(thrownError); //alert with HTTP error
$('.animation_image').hide(); //hide loading image
loading = false;
});
}
}
});
});
</script>
伙计们,请帮我一下吧。可能有'
$(window).scrollTop()+ $(window).height()== $(document).height()`这个部分存在某种问题。
我要跟踪的部分不是窗口的滚动。
建议你使用这个插件:http://imakewebthings.com/jquery-waypoints/ – jacquard