Home >Web Front-end >JS Tutorial >jQuery method to dynamically load content when the page is scrolled_jquery

jQuery method to dynamically load content when the page is scrolled_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 16:08:231223browse

The example in this article describes how jQuery implements dynamic loading of content when the page is scrolled. Share it with everyone for your reference. The specific analysis is as follows:

Many websites, such as twitter and JD.com homepage, will dynamically load the page content when the page scrolls to a certain position. This can speed up the opening of the page and save bandwidth. The following JS code can help you do it. arrive.

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 will be helpful to everyone’s jQuery programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn