jQuery implements the method of dynamically loading content when the page is scrolling
- 2020-05-19 04:05:06
- OfStack
This article demonstrates an example of how jQuery can dynamically load content when a page is scrolling. Share with you for your reference. The specific analysis is as follows:
Many websites, such as twitter and the home page of jingdong mall, will dynamically load the page content when the page scrolls to a certain position, which can speed up the page opening and save bandwidth. The JS code below can help you do this.
var loading = false;
$(window).scroll(function(){
if((($(window).scrollTop()+$(window).height())+250)>=$(document).height()){
if(loading == false){
loading = true;
$('#loadingbar').css("display","block");
$.get("load.php?start="+$('#loaded_max').val(), function(loaded){
$('body').append(loaded);
$('#loaded_max').val(parseInt($('#loaded_max').val())+50);
$('#loadingbar').css("display","none");
loading = false;
});
}
}
});
$(document).ready(function() {
$('#loaded_max').val(50);
});
I hope this article has been helpful to your jQuery programming.